因为一个“。”WA了好几遍
我能不能再认真一点啊服了
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
bool gra[111][111];
int clo[111];
int ans,n;
bool finsh = false;
bool check( int id, int sta)
{
for( int i = 0; i < n; i++)
if( gra[id][i] && sta == clo[i])
return false;
return true;
}
void dfs( int id, int sum)
{
if(id >= n || ans > 4)
finsh = true;
if(finsh)
return ;
for( int i = 1; i <= sum ;i++)
{
if(check(id, i))
{
clo[id] = i;
dfs( id + 1, sum);
clo[id] = 0;
}
}
if( !finsh )
{
ans++;
dfs(id,sum + 1);
}
}
int main()
{
char s[150];
while( ~scanf("%d",&n),n )
{
memset(clo,0,sizeof(clo));
memset(gra,0,sizeof(gra));
finsh = false;
ans = 1;
getchar();
int st, len, i , j, end;
for( i=1; i <= n ;i++)
{
gets(s);
len = strlen(s);
st = s[0] - 'A';
for( j = 2; j < len; j++)
{
end = s[j] - 'A';
gra[st][end] = true;
}
}
dfs(0,1);
if(ans == 1)
printf("1 channel needed.\n",ans);
else
printf("%d channels needed.\n",ans);
}
return 0;
}