|
|
back to boardWho can tell me what's wrong with my program? Posted by sun yi 9 Apr 2002 19:41 #include <fstream.h> #include <string.h> int n,m=0; int g[20][3],ans=0,f[20]={0},sum=0; //ifstream input("input.txt"); void search(int k) { int i; if (k>n) { if (sum>ans) ans=sum; return; } search(k+1); for (i=0;i<3&&!f[g[k][i]];i++); if (i==3) { for (i=0;i<3;i++) f[g[k][i]]=1; sum++; search(k+1); for (i=0;i<3;i++) f[g[k][i]]=0; sum--; } return; }
main(void) { int i,j,k; char name[100][100],s[100]; //cin=input; cin>>n; for (i=1;i<=n;i++) for (j=0;j<3;j++) { cin>>s; while (s[0]==0) cin>>s; for (k=1;k<=m;k++) if (strcmp(name[k],s)==0) break; if (k>m) { m++; memcpy(name[m],s,100); } g[i][j]=k; } search(1); cout<<ans<<endl; } |
|
|