最大团问题
2015-11-07 16:14
701 查看
讲解就在这里http://www.cnblogs.com/zhj5chengfeng/archive/2013/07/29/3224092.html
说的很清晰,列举的题目也比较简单
重要的几个结论
1、最大团点的数量=补图中最大独立集点的数量
2、二分图中,最大独立集点的数量+最小覆盖点的数量=整个图点的数量
3、二分图中,最小覆盖点的数量=最大匹配的数量
4、图的染色问题中,最少需要的颜色的数量=最大团点的数量
模板
ZOJ 1492 MAXClique
给了一个最多包含 50 个点的无向图,让求这个图中最大团所包含的的点的数量
直接按照上面所讲的 DFS 过程做就行
View Code
说的很清晰,列举的题目也比较简单
重要的几个结论
1、最大团点的数量=补图中最大独立集点的数量
2、二分图中,最大独立集点的数量+最小覆盖点的数量=整个图点的数量
3、二分图中,最小覆盖点的数量=最大匹配的数量
4、图的染色问题中,最少需要的颜色的数量=最大团点的数量
模板
ZOJ 1492 MAXClique
给了一个最多包含 50 个点的无向图,让求这个图中最大团所包含的的点的数量
直接按照上面所讲的 DFS 过程做就行
#include <map> #include <set> #include <list> #include <cmath> #include <ctime> #include <deque> #include <stack> #include <queue> #include <cctype> #include <cstdio> #include <string> #include <vector> #include <climits> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> #define LL unsigned long long #define PI 3.1415926535897932626 typedef long long type; using namespace std; type gcd(type a, type b) {return b == 0 ? a : gcd(b, a % b);} const int MAXN = 110; struct Max_Clique { int G[MAXN][MAXN]; int N,MAX[MAXN],Alt[MAXN][MAXN],ans; void init(int n) { N = n; } bool dfs(int cur,int tot) { if (cur == 0) { if (tot > ans) { ans = tot; return true; } return false; } for (int i = 0 ; i < cur ; i++) { if (cur - i + tot <= ans) return false; int u = Alt[tot][i]; if (MAX[u] + tot <= ans) return false; int nxt = 0; for (int j = i + 1 ; j < cur ; j++) if (G[u][Alt[tot][j]]) Alt[tot + 1][nxt++] = Alt[tot][j]; if (dfs(nxt,tot + 1)) return true; } return false; } int MaxClique() { ans = 0; memset(MAX,0,sizeof(MAX)); for (int i = N - 1 ; i >= 0 ; i--) { int cur = 0; for (int j = i + 1 ; j < N ; j++) { if (G[i][j]) Alt[1][cur++] = j; } dfs(cur,1); MAX[i] = ans; } return ans; } }slover; int main() { int N; while (scanf("%d",&N) != EOF) { if (N == 0) break; slover.init(N); char str[5010]; memset(slover.G,0,sizeof(slover.G)); for (int i = 0 ; i < N ; i++) { scanf("%s",str); int len = strlen(str); for (int j = 2 ; j < len ; j++) { int id = str[j] - 'A'; slover.G[i][id] = slover.G[id][i] = true; } } int ret = slover.MaxClique(); if (ret == 1) printf("1 channel needed.\n"); else printf("%d channels needed. \n", ret); } return 0; }
View Code
相关文章推荐
- html向flash传递参数
- IE8及以下浏览器伪数组slice方法兼容处理
- 修改mysql DataDir方式
- 导航条菜单的制作(笔记)
- [19]结构体
- [20]枚举
- ANT教程之二 ANT环境安装设置
- C# 字符串操作--减少垃圾回收压力
- C# 字符串操作--减少垃圾回收压力
- [18]指针
- windows下安装numpy模块不成功解决办法
- Android之Socket通信、List加载更多、Spinner下拉列表
- D3D绘制2D图像例子
- [18]字符串
- ANT教程之一 ANT简介
- 乔里斯基分解(Cholesky decomposition)
- c语言链表
- [转]iOS容易造成循环引用的三种场景,就在你我身边!
- 回溯算法 Backtrack
- 继承 完整的初始化方法和便利构造器