最大团
http://acm.hdu.edu.cn/showproblem.php?pid=1530
1 #include <cstdio> 2 #include <cstdlib> 3 #include <cmath> 4 #include <cstring> 5 #include <time.h> 6 #include <string> 7 #include <set> 8 #include <map> 9 #include <list> 10 #include <stack> 11 #include <queue> 12 #include <vector> 13 #include <algorithm> 14 #include <iostream> 15 using namespace std; 16 #define ll long long 17 #define minv 1e-6 18 #define inf 1e9 19 #define pi 3.1415926536 20 const ll mod=1e9+7;//998244353 21 const long maxn=5e1+5; 22 23 int a[maxn][maxn],g=0,f[maxn],maxg=0; 24 25 bool judge(int i) 26 { 27 int j; 28 for (j=1;j<=g;j++) 29 if (a[f[j]][i]==0) 30 return 0; 31 return 1; 32 } 33 34 35 void dfs(int i) 36 { 37 if (i==0) 38 maxg=max(maxg,g); 39 if (g+i<=maxg) 40 return; 41 if (judge(i)) 42 { 43 g++; 44 f[g]=i; 45 dfs(i-1); 46 g--; 47 } 48 dfs(i-1); 49 } 50 51 int main() 52 { 53 int n,i,j; 54 while (1) 55 { 56 scanf("%d",&n); 57 if (n==0) 58 break; 59 g=0; 60 maxg=0; 61 for (i=1;i<=n;i++) 62 for (j=1;j<=n;j++) 63 scanf("%d",&a[i][j]); 64 dfs(n); 65 printf("%d\n",maxg); 66 } 67 return 0; 68 }