您的位置:首页 > 其它

1208. Legendary Teams Contest

2012-10-19 16:47 92 查看
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
[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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: