标签:queue iostream ace pairs bre height eof image log
问题描述:团就是最大完全子图。
给定无向图G=(V,E)。如果UV,且对任意u,v
U 有(u,v)
E,则称U 是G 的完全子图。
G 的完全子图U是G的团当且仅当U不包含在G 的更大的完全子图中,即U就是最大完全子图。
G 的最大团是指G中所含顶点数最多的团。
这里可使用加入DP后的优化算法
#include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<algorithm> #include<cstring> #include<string> #include<vector> #include<map> #include<set> #include<queue> using namespace std; int n,path[61][61],s[61],ans,dp[61]; bool is_clique(const int end,const int point) { int i; for (i=1;i<end;i++) if (!path[s[i]][point]) return false; return true; } void dfs(int depth,int now) { if (depth+n-now+1<=ans||depth+dp[now]<=ans) return; int i; for (i=now;i<=n;i++) { if (is_clique(depth+1,i)) { s[depth+1]=i; dfs(depth+1,i+1); } } if (depth>ans) ans=depth; } int main() { while (~scanf("%d",&n)) { if (n==0) break; int i,j; for (i=1;i<=n;i++) for (j=1;j<=n;j++) scanf("%d",&path[i][j]); memset(dp,0,sizeof(dp)); ans=0; dp[n]=1; for (i=n-1;i>=1;i--) { s[1]=i; dfs(1,i+1); dp[i]=ans; } printf("%d\n",dp[1]); } return 0; }
标签:queue iostream ace pairs bre height eof image log
原文地址:http://www.cnblogs.com/hnqw1214/p/6347680.html