先上最大团定义:

最大团问题(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. MSSQL 常用内置函数

    一.判断表是否存在 IF objectproperty(object_id(@tableName),'IsUserTable') IS NOT NULL PRINT '存在' ELSE PRINT ' ...

  2. JavaScript原型链与继承

    最近学习了<Javascript高级程序设计>面向对象部分,结合书中的例子总结一下原型链和继承部分的内容. 创建对象 在Js当中没有类这个概念,当我们想要创建具有相同属性的对象的时候,有如 ...

  3. jQuery -&gt; end方法的使用方法

    我们在对结果集使用find.filter等方法时,会改变结果集. 这样的改变原先结果集的方法被称作destructive jQuery method jQuery cookbook有例如以下定义: A ...

  4. RMAN传输表空间迁移数据

    实验环境: 源数据库:oracle 10g(Release 10.2.0.1.0) 目标数据库:oracle 10g(Release 10.2.0.1.0) 待传输的表空间:TEST 1.在tes ...

  5. java学习笔记day07

    1.throwable下面的子类分为两大类:Error 和 Exception 2.如果方法上有throws Exception,则必须对异常进行处理:  try{    需要检测异常代码     } ...

  6. JQ 更改li 颜色

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. differ比较两个字符串的差异

    "abcde","abdefk"  ---->-c,+f,+k "aba","aababb"    -----&g ...

  8. pl sql练习(4)

    1.ROW_NUMBER 返回连续的排位,不论值是否相等 select deptno,ename,sal, row_number () over (partition by deptno order ...

  9. HDU 5793 - A Boring Question

    HDU 5793 - A Boring Question题意: 计算 ( ∑(0≤K1,K2...Km≤n )∏(1≤j<m) C[Kj, Kj+1]  ) % 1000000007=? (C[ ...

  10. B - A + B Again

    Description There must be many A + B problems in our HDOJ , now a new one is coming.         Give yo ...