【HDU - 1530】Maximum Clique(最大团问题,图论)
題干:
Given a graph G(V, E), a clique is a sub-graph g(v, e), so that for all vertex pairs v1, v2 in v, there exists an edge (v1, v2) in e. Maximum clique is the clique that has maximum number of vertex.?
Input
Input contains multiple tests. For each test:?
The first line has one integer n, the number of vertex. (1 < n <= 50)
The following n lines has n 0 or 1 each, indicating whether an edge exists between i (line number) and j (column number).?
A test with n = 0 signals the end of input. This test should not be processed.?
Output
One number for each test, the number of vertex in maximum clique.?
Sample Input
5 0 1 1 0 1 1 0 1 1 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 0Sample Output
4解題報告:
? 暴力dfs+剪枝。(然而剪枝并不能快多少,也就快了200ms左右)
AC代碼:(4134ms)
#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define F first #define S second #define ll long long #define pb push_back #define pm make_pair using namespace std; typedef pair<int,int> PII; const int MAX = 55 + 5; int a[MAX][MAX]; int bk[MAX]; int n,ans; void dfs(int cur,int tmp) {if(cur == n+1) {ans = max(ans,tmp);return;}int tar = cur+1;dfs(tar,tmp);for(int j = 1; j<=tmp; j++) {if(a[tar][bk[j]] == 0) return;}bk[tmp+1] = tar;dfs(tar,tmp+1); } int main() {while(~scanf("%d",&n) && n) {ans = 0;memset(a,0,sizeof a);for(int i = 1; i<=n; i++) {for(int j = 1; j<=n; j++) scanf("%d",&a[i][j]);}dfs(0,0);printf("%d\n",ans);}return 0 ; }?
總結
以上是生活随笔為你收集整理的【HDU - 1530】Maximum Clique(最大团问题,图论)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 光大炎黄信用卡金卡额度是多少 客服热线是
- 下一篇: pts.exe - pts是什么进程 有