日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

【HDU - 1530】Maximum Clique(最大团问题,图论)

發(fā)布時(shí)間:2023/12/10 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【HDU - 1530】Maximum Clique(最大团问题,图论) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

題干:

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 0

Sample Output

4

解題報(bào)告:

? 暴力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 ; }

?

總結(jié)

以上是生活随笔為你收集整理的【HDU - 1530】Maximum Clique(最大团问题,图论)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。