先上最大团定义:

最大团问题(Maximum Clique Problem, MCP)是图论中一个经典的组合优化问题,也是一类NP完全问题,在国际上已有广泛的研究,而国内对MCP问题的研究则还处于起步阶段,因此,研究最大团问题具有较高的理论价值和现实意义。

最大团问题又称为最大独立集问题(Maximum Independent Set Problem)。启发式算法。确定性算法有回溯法分支限界法等,启发式算法、蚁群算法、顺序贪婪算法、DLS-MC算法和智能搜索算法等。

给定无向图G=(V,E)。如果UV,且对任意u,vU
有(u,v)  E,则称U 是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.

独立思考算法:

n<=50
深搜? dfs(p); visit[p]=1;
1.
for(int i=1;i<=n;i++)
if(visit[i]==1)
dfs(i);
2.然后假设 i这个点就是在大团里面的啦:
如果存在 map[i][k]=0;
visit[k]=0; 代表不能选取(回溯时记得标志清理干净)
for(int i=1;i<=n;i++)
if(visit[i]==1)
dfs(i);
最后数visit的1的数目更新答案..... 显然这是暴力算法...不过先写一发,看看有多暴力


10s都T了...好怕怕。。

怎么优化?

最优化剪枝:      ans-现在团中节点>可加入节点(加入该剪枝已经可以过)
好吧 以递增顺序枚举点才是搜索剪枝王道
 1 2 3 4 5 这个状态就有  5!个不同的顺序描述方式
代码
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map> using namespace std; const int MAXN=60;
int N;
int Path[MAXN][MAXN];
int Set[MAXN];//用以寻找一个可能集合
int Ans; //判断新点是否与原集合里的点互相连通
bool is_clique( const int end, const int point )
{
for( int i=1; i<end; ++i )
{
if( !Path[ Set[i] ][point] )
{
return false;
}
}
return true;
}
//递归查找,查找算法简单明了,不再详说
void dfs( int depth, int now )
{
if( depth+N-now+1 <= Ans )
{
return;
}
for( int i=now; i<=N; ++i )
{
if( is_clique(depth+1, i) )
{
Set[depth+1]=i;
dfs( depth+1, i+1 );
}
}
if( depth > Ans )
{
Ans=depth;
}
}
int main()
{
freopen("in","r",stdin); while( scanf("%d", &N)!=EOF && N )
{
for( int i=1; i<=N; ++i )
{
for( int j=1; j<=N; ++j )
{
scanf("%d", &Path[i][j]);
}
}
Ans=0;
dfs( 0, 1 );
printf("%d\n", Ans);
}
return 0;
}
//还可以设置一个DP[MAXN],用以记录i~N点集合里最大团数,可以利用这一点剪枝. DP[n]=DP[n+1]+1 or DP[n+1];


有点慢 尝试加入DP剪枝。

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map> using namespace std; const int MAXN=60;
int N;
int Path[MAXN][MAXN];
int Set[MAXN];//用以寻找一个可能集合
int Ans;
int DP[MAXN];
//判断新点是否与原集合里的点互相连通
bool is_clique( const int end, const int point )
{
for( int i=1; i<end; ++i )
{
if( !Path[ Set[i] ][point] )
{
return false;
}
}
return true;
}
//递归查找,查找算法简单明了,不再详说
void dfs( int depth, int now )
{
if( depth+N-now+1 <= Ans||depth+DP[now] <=Ans )
{
return;
}
for( int i=now; i<=N; ++i )
{
if( is_clique(depth+1, i) )
{
Set[depth+1]=i;
dfs( depth+1, i+1 );
}
}
if( depth > Ans )
{
Ans=depth;
}
}
int main()
{
// freopen("a.in","r",stdin); while( scanf("%d", &N)!=EOF && N )
{
for( int i=1; i<=N; ++i )
{
for( int j=1; j<=N; ++j )
{
scanf("%d", &Path[i][j]);
}
}
memset(DP,0,sizeof(DP));
Ans=0;
DP[N]=1;
for(int i=N-1;i>=1;i--)
{
Set[1]=i;
dfs( 1, i+1 );
DP[i]=Ans;
}
printf("%d\n", DP[1]);
}
return 0;
}

并没有多大效果...但是还是少了1s 不错了

【最大团】【HDU1530】【Maximum Clique】的更多相关文章

  1. HDU1530 Maximum Clique dp

    正解:dp 解题报告: 这儿是传送门 又是个神仙题趴QAQ 这题就直接说解法辣?主要是思想比较难,真要说有什么不懂的知识点嘛也没有,所以也就没什么好另外先提一下的知识点QAQ 首先取反,就变成了求最大 ...

  2. 回溯法——最大团问题(Maximum Clique Problem, MCP)

    概述: 最大团问题(Maximum Clique Problem, MCP)是图论中一个经典的组合优化问题,也是一类NP完全问题.最大团问题又称为最大独立集问题(Maximum Independent ...

  3. Maximum Clique

    Maximum Clique Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...

  4. hdu 1530 Maximum Clique (最大包)

    Maximum CliqueTime Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  5. maximum clique 1

    maximum clique 1 时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 262144K,其他语言524288KSpecial Judge, 64bit IO Format: % ...

  6. 2019牛客多校第五场 F maximum clique 1 状压dp+最大独立集

    maximum clique 1 题意 给出一个集合s,求每个子集的最大独立集的权值和(权值是独立集的点个数) 分析 n比较小,一股浓浓的暴力枚举每一个子集的感觉,但是暴力枚举模拟肯定会T,那么想一想 ...

  7. ZOJ 1492 Maximum Clique 搜索最大团

    ZOJ1492 题意:给一个无向图 求最大团的大小.节点数小于50 数据有限,考虑记忆化搜索,方程很好给出. 令 Si={vi,vi+1.....vn} mc[i]表示Si最大团的大小,倒着推算. 必 ...

  8. 【HDU1530】【ZOJ1492】Maximum Clique

    Position: http://poj.org/problem?id=3241 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCod ...

  9. 2019 牛客多校五 F. maximum clique 1 (最大团)

    大意: 给定$n$个互不相同的数, 若两个数异或后二进制中$1$的个数不少于$2$则连边, 求最大团. 最大团转为补图最大独立集. 可以发现补图是二分图, 所以直接$dinic$即可. 最大独立集相当 ...

随机推荐

  1. 456. 132 Pattern

    456. 132 Pattern Given an array of integers a1, a2, a3-an, judge if there exists the 132 pattern. 13 ...

  2. Unity 为自己组件添加公共方法

    为什么需要跟你的组件添加公共方法呢? 留一条后路嘛,万一你那天想起要给全部的组件添加一个方法. 此时我只能告诉你慢慢修改吧累死你 子组件:A ,父组件:B继承方式:  A -> B –> ...

  3. Struts2(二)——配置文件struts2.xml的编写

    接上一篇博客,这篇博客讲述一下2——9小标题的内容,这些问题都可以在struts2配置文件中设置(当然有的也可以在Struts.properties属性文件,web.xml中进行设置),而且常规开发中 ...

  4. c语言的lua库编写

    gcc编译 gcc -I/usr/local/include/ -L/usr/local/lib/ -lm -o engine_mlisten_lua ./src/engine_mlisten_lua ...

  5. android——生成或者下载的图片在相册中找不到

    今天在写程序的时候,遇到了一个问题,就是生成的图片一直都不能在相册中显示出来,而且,就连通过发送Intent过去,都找不到.通过在网上搜索,发现了一个很好的方法. Intent intent = ne ...

  6. JSON入门之二:org.json的基本用法

    java中用于解释json的主流工具有org.json.json-lib与gson,本文介绍org.json的应用. 官方文档: http://www.json.org/java/ http://de ...

  7. BottomSheetBehavior 之 java.lang.IllegalArgumentException: The view is not associated with BottomSheetBehavior

    AndroidRuntime: FATAL EXCEPTION: main Process: me.chunsheng.uberdriver, PID: 13674 java.lang.Runtime ...

  8. [makefile] filter-out

    $(filter-out ,) 名称:反过滤函数——filter-out.功能:以模式过滤字符串中的单词,去除符合模式的单词.可以有多个模式.返回:返回不符合模式的字串.示例: objects=mai ...

  9. Spring 系列: Spring 框架简介(转载)

    Spring 系列: Spring 框架简介 http://www.ibm.com/developerworks/cn/java/wa-spring1/ Spring AOP 和 IOC 容器入门 在 ...

  10. Pet--hdu4707

    Pet Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...