#include<iostream>
#include<stdio.h>
#include<string>
#define MAXN 60
using namespace std;
int max_clique(int n, int * * mat, int *ret) ;
int main()
{
//freopen("acm.acm","r",stdin);
int i;
int ans;
int j;
string s;
int num;
int * * _m;
int * ret;
while(cin>>num)
{
if(num == )
break;
_m = new int * [num];
ret = new int[num];
for(i = ; i < num; ++ i)
{
_m[i] = new int[num];
memset(_m[i],,sizeof(int)*num);
}
//for(i = 0; i < num; ++ i)
// for(j = 0; j < num; ++ j)
// cout<<_m[i][j]<<" ";
for(i = ; i < num; ++ i)
{
cin>>s;
if(s.length() == )
continue;
else
{
for(j = ; j < s.length(); ++ j)
{
_m[s[] - 'A'][s[j] - 'A'] = ;
}
}
}
ans = max_clique(num,_m,ret);
cout<<ans;
if(ans == )
cout<<" channel needed."<<endl;
else
cout<<" channels needed."<<endl;
delete [] _m;
delete ret;
}
} void clique(int n, int* u, int * * mat, int size, int& max, int& bb, int * res, int* rr, int* c) {
int i, j, vn, v[MAXN];
if (n) {
if (size + c[u[]] <= max) return;
for (i = ; i < n + size - max && i < n; ++ i) {
for (j = i + , vn = ; j < n; ++ j)
if (mat[u[i]][u[j]])
v[vn ++] = u[j];
rr[size] = u[i];
clique(vn, v, mat, size + , max, bb, res, rr, c);
if (bb) return;
}
} else if (size > max) {
max = size;
for (i = ; i < size; ++ i)
res[i] = rr[i];
bb = ;
}
} int max_clique(int n, int * *mat, int * ret) {
int max = , bb, c[MAXN], i, j;
int vn, v[MAXN], rr[MAXN];
for (c[i = n - ] = ; i >= ; -- i) {
for (vn = , j = i + ; j < n; ++ j)
if (mat[i][j])
v[vn ++] = j;
bb = ;
rr[] = i;
clique(vn, v, mat, , max, bb, ret, rr, c);
c[i] = max;
}
return max;
}
关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。
技术网站地址: vmfor.com