http://acm.timus.ru/problem.aspx?space=1&num=1208

水题

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<algorithm>
#include<cmath>

using namespace std;
//#pragma comment(linker,"/STACK:1000000000,1000000000")

#define LL long long

const int INF=0x3f3f3f3f;
const int N=35;
int num[N][5];
bool select[N*N];
map<string,int>str;
int n,ans;
void dfs(int x,int k)
{
    if(x==n)
    {
        ans=max(ans,k);
        return ;
    }
    dfs(x+1,k);
    int j;
    for(j=0;j<3;++j)
    if(select[num[x][j]]==true)
    return;
    for(j=0;j<3;++j)
    select[num[x][j]]=true;
    dfs(x+1,k+1);
    for(j=0;j<3;++j)
    select[num[x][j]]=false;
}
int main()
{
    while(cin>>n)
    {
        str.clear();
        int I=0;
        for(int i=0;i<n;++i)
        for(int j=0;j<3;++j)
        {
            string stmp;
            cin>>stmp;
            if(str.find(stmp)==str.end())
            {str[stmp]=I;num[i][j]=I++;}
            else
            num[i][j]=str[stmp];
        }
        ans=0;
        memset(select,false,sizeof(select));
        dfs(0,0);
        cout<<ans<<endl;
    }
    return 0;
}

 

posted on 2012-10-19 16:47  夜->  阅读(199)  评论(0编辑  收藏  举报