[HDU 1530] Maximum Clique 最大团
2015-08-21 13:34
393 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1530
题意:以邻接矩阵方式输入一个图,求图的最大完全子图。
思路:最大团,狠暴力的算法。直接贴模板
题意:以邻接矩阵方式输入一个图,求图的最大完全子图。
思路:最大团,狠暴力的算法。直接贴模板
[code]#include <stack> #include <cstdio> #include <vector> #include <cstring> #include <algorithm> using namespace std; int n, res; bool vis[55]; int num[55];//每个点的子结点数 int mapn[55][55]; //邻接矩阵 int Dfs(int rt, int sum) { if(rt > n){ if(sum > res) res = sum; return 0; } if(sum + n - rt < res) return 0; if(sum > num[rt]){ Dfs(rt+1, sum); return 0; } int i; for(i = 1; i < rt; i++){ if(vis[i] && !mapn[i][rt]) break; } if(i == rt){ vis[rt] = true; Dfs(rt+1, sum+1); vis[rt] = false; } Dfs(rt+1, sum); return 0; } int main() { while(~scanf("%d", &n) && n){ memset(num, 0, sizeof(num)); for(int i = 1; i <= n; i++){ vis[i] = false; for(int k = 1; k <= n; k++){ scanf("%d",&mapn[i][k]); num[i] += mapn[i][k]; } } res=0; Dfs(1, 0); printf("%d\n",res); } return 0; }
相关文章推荐
- Espresso实战:快速的Android UI自动化测试
- 辛星简译MySQL中的last_query_cost
- @GeneratedValue 四种标准用法为TABLE,SEQUENCE,IDENTITY,AUTO.
- C#中的属性(get、set、value)
- C#中的属性(get、set、value)
- The GNU configure and build system-configure的详细介绍
- UITableView 多层详解
- UITextfield后面只能输入小数点后2位
- IOS UIPageControl(分页控制器) 用法总结
- Android常用UI组件属性和.9图制作
- INDEX && PRIMARY KEY && UNIQUE KEY
- HDU 5412 CRB and Queries【整体二分+树状数组】
- 根据字体多少使UILabel自动调节尺寸
- 被忽略的 UITableViewHeaderFooterView
- Android UI--Action Bar
- iOS UIView动画实践(五):Keyframe Animation
- 从request中获取上一个请求的url
- UIButton透明度
- 蓝牙UUID及其128位换算
- Circular Queue--循环队列