求一个图中的最大团(全连通分量) n = 40 (中途相遇法)
来源:互联网 发布:电脑连接不到网络 编辑:程序博客网 时间:2024/06/15 03:38
给出一个图,求图中的最大团,n = 40,应该怎么求呢?
我们可以使用中途相遇法,将原有的40个点分为两部分,每部分各20个点。在此之后,我们可以先对前20个点求出暴力求出所有团。设dp[mask]表示当前选择点的状态为mask(状态压缩)时的最大团数量。则在求整体最大团时,若得到后20个点中的当前团为p,找到在前二十个点中所有与p中所有点都有边的点集q,则maxc = max(maxc, dp[q] + p)。这样,我们就可以求出最大团的大小。
另见:http://blog.csdn.net/mosquito_zm/article/details/77170715
cf 题解版:We can find the maximal clique by the "meet in the middle" approach. Divide the vertices of the graph into 2 sets with equal number of vertices in each set(if n is odd, one set will have a vertex more than the other). We can save the maximal clique for each subset of the first set in dp[mask]. Now ,for each clique C in the second set, let v1, ... , vt be vertices in the first set that are connected to all of the vertices of C. Then m = max(m, dp[mask(v1, ... , vt)] + sizeof(C)) (m is size of maximum clique). Note : finding the maximal clique is also possible by a wise brute forces.
cf题目代码如下:
#include <bits/stdc++.h>#define ll long longusing namespace std;const int maxn = 40;const int C = 20;int dp[1 << C];ll adj[maxn];int n,m,k,x;int maxc(){for(int i = 0;i < n;i++){for(int j = 0;j < n;j++){scanf("%d",&x);adj[i] |= (ll)(i == j || x) << j;}}for(int i = 1;i < (1 << max(0,n - C));i++){int x = i;for(int j = 0;j < C;j++)if((i >> j) & 1)x &= adj[j + C] >> C;if(x == i) dp[i] = __builtin_popcount(i);}for(int i = 1;i < (1 << max(0,n - C));i++)for(int j = 0;j < C;j++)if((i >> j) & 1)dp[i] = max(dp[i], dp[i ^ (1 << j)]);int ans = 0;for(int i = 0;i < (1 << min(C,n));i++){int x = i,y = (1 << max(0, n - C)) - 1;for(int j = 0;j < min(C,n);j++)if((i >> j) & 1) x &= adj[j] & ((1 << C) - 1),y &= adj[j] >> C;if(x != i) continue;ans = max(ans, __builtin_popcount(i) + dp[y]);}return ans;}int main(){scanf("%d",&n);scanf("%d",&k);int tmp = maxc();long double x = (long double) k / tmp;ll ans = tmp * (tmp - 1) / 2;cout << fixed << setprecision(8) << x * x * ans << '\n';return 0;}
- 求一个图中的最大团(全连通分量) n = 40 (中途相遇法)
- Codeforces Round #428 (Div. 2) E 推理+求最大团(中途相遇法)(状态压缩)(代码能力)
- 最大团,白书P323UVa11324(有向图强连通分量,dp求GVA权最大路径)
- UVa 11324 最大团(强连通分量+dp最长路)
- 强连通分量,DAG上的最长路,记忆化搜索(最大团,UVA 11324)
- 中途相遇法(侏罗纪,LA 2965)
- poj2549 Sumsets(中途相遇法)
- 例题25(侏罗纪)(中途相遇法)!
- Uva 10125 Sumsets(中途相遇法,高效枚举)
- UVa 10125 - Sumsets 解题报告(中途相遇法)
- HDU-4963 Dividing a String (枚举[中途相遇法])
- codeforces808E(超大背包的解决问题,中途相遇法)
- uva 1326 Jurassic Remains(中途相遇法+位运算)
- uva10125 (中途相遇法)
- 中途相遇法
- CF888E:Maximum Subsequence(中途相遇)
- 求连通分量(无向图,邻接矩阵,BFS)
- 求连通分量-方法1(图论算法)
- A Microservice Architecture with Spring Boot and Spring Cloud(二)
- free函数的详解
- Vue学习笔记
- MySQL配置文件mysql.ini参数详解
- python怎么给实例对象添加方法?
- 求一个图中的最大团(全连通分量) n = 40 (中途相遇法)
- Mapreduce框架的相关问题
- linux下tomcat和solr服务器整合笔记
- Java集合---ConcurrentHashMap原理分析
- Unity 回合制战斗系统(中级篇)-进阶
- mysql alter 语句用法,添加、修改、删除字段等
- 《去哪网编程题》统计字符
- jQuery动画的hover连续触发动画bug处理
- iOS MotionManager(运动管理器)~demo