hdu1530 Maximum Clique
2016-02-14 16:18
344 查看
Maximum Clique
Problem DescriptionGiven 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
Author
CHENG, Long
最大团模板题
#include<bits/stdc++.h> using namespace std; const int maxn=51; int num[maxn]; int G[maxn][maxn],ret; bool dfs(int *adj,int tot,int cnt){ if(tot==0){ if(cnt>ret){ ret=cnt; return 1; } return 0; } for(int i=0;i<tot;i++){ if(cnt+tot-i<=ret) continue; if(cnt+num[adj[i]]<=ret) continue; int t[maxn],k=0; for(int j=i+1;j<tot;j++){ if(G[adj[i]][adj[j]]) t[k ++] = adj[j]; } if(dfs(t,k,cnt+1)) return 1; } return 0; } void Maxclique(int n){ int adj[maxn],tot; for(int i=n;i>=1;i--){ tot=0; for(int j=i+1;j<=n;j++) if(G[i][j]==1) adj[tot++]=j; dfs(adj,tot,1); num[i]=ret; } } int main(){ int n; while(scanf("%d",&n)!=EOF){ if(n==0) break; memset(G,0,sizeof(G)); ret=0; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) scanf("%d",&G[i][j]); Maxclique(n); printf("%d\n",ret); } return 0; }
相关文章推荐
- Arduino代码机制-Arduino.h
- Android开发中无处不在的设计模式——Builder模式
- POJ 2524 Ubiquitous Religions
- Longest Increasing Subsequence
- ruiaijun人工智能理论纪录片:《反射算法与离散智能编程》《自编程自主学习算法》
- poj2926 Requirements
- API Guides(二)——Activity To AIDL
- iOS7 iOS8 UITableviewCell处于编辑状态,dismiss或者back崩溃
- WeUI logo专为微信设计的 UI 库 WeUI
- 在一般处理文件中访问Session需要添加IRequiresSessionState
- BlockingQueue简介
- 编译ionic项目的时候提示: Please install the Android build tools version 19.1.0 or higher.
- squirrel sql client 连接phoenix
- EasyUi 中datagrid 实现查询方法
- rpmbuild常用命令
- cf#ecr7-A. Infinite Sequence-暴力/二分-数学
- jmeter jdbc request使用详解
- 11.UIView的transform属性
- 【摘】 pt-query-digest工具一解
- UILabel textAlignment 居中 左右对齐