zoj1492 最大团
Maximum Clique
Time Limit: 10 Seconds Memory Limit: 32768 KB
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.
Input
Input contains multiple tests. For each test:
The first line has one integer n, the number of vertex. (1 < n <= 50)
The following n lines has n 0 or 1 each, indicating whether an edge exists between i (line number) and j (column number).
A test with n = 0 signals the end of input. This test should not be processed.
Output
One number for each test, the number of vertex in maximum clique.
Sample Input
5
0 1 1 0 1
1 0 1 1 1
1 1 0 1 1
0 1 1 0 1
1 1 1 1 0
0
Sample Output
4
模板题,学习一下模板。
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define INF 1000000001
#define MOD 1000000007
#define ll long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define pi acos(-1.0)
using namespace std;
const int MAXN = ;
int mp[MAXN][MAXN],n,maxv[MAXN],ans,a[MAXN][MAXN];//maxv[]表示节点"i到n"能够构成的最大团节点个数、
//a[i][]表示i已经在最大团内的时候,还可能有多少个节点能够加入到最大团中。
int dfs(int cur,int x)//x指递归层数 也就是dfs树的层数 也就是最大团的节点个数
{
if(cur == ){
if(x > ans){
ans = x;
return ;
}
return ;
}
for(int i = ; i < cur; i++){
if(cur - i + x <= ans)return ;//假设集合x中的所有点都是在当前的团中 但是个数还是小于已知的值 不必处理
int u = a[x][i];
if(maxv[u] + x <= ans)return ;//由于我们是从大到小求出答案的 所以这里u有可能之前已经求过。所以这时候可以减枝
//maxv[u]说明后面所有可能的最大值已经不能比结果大了 不必在处理
int num = ;
for(int j = i + ; j < cur; j++){
if(mp[u][a[x][j]])a[x+][num++] = a[x][j];
}
if(dfs(num,x+))return ;//一旦找到值就可以返回 因为后面的点所含的点数只会越来越少
}
return ;
}
void solve()
{
ans = ;
memset(maxv,,sizeof(maxv));
for(int i = n; i >= ; i --){
int cur = ;
for(int j = i + ; j <= n; j++){
if(mp[i][j]){
a[][cur++] = j;
}
}
dfs(cur,);
maxv[i] = ans;
}
printf("%d\n",ans);
}
int main()
{
while(~scanf("%d",&n)){
if(!n)break;
for(int i = ; i <= n; i++){
for(int j = ; j <= n; j++){
scanf("%d",&mp[i][j]);
}
}
solve();
}
return ;
}
zoj1492 最大团的更多相关文章
- ZOJ 1492 Maximum Clique 搜索最大团
ZOJ1492 题意:给一个无向图 求最大团的大小.节点数小于50 数据有限,考虑记忆化搜索,方程很好给出. 令 Si={vi,vi+1.....vn} mc[i]表示Si最大团的大小,倒着推算. 必 ...
- 代码的坏味道(5)——数据泥团(Data Clumps)
坏味道--数据泥团(Data Clumps) 特征 有时,代码的不同部分包含相同的变量组(例如用于连接到数据库的参数).这些绑在一起出现的数据应该拥有自己的对象. 问题原因 通常,数据泥团的出现时因为 ...
- 软件海贼团 OnePiece (版权所有)
最近迷上了“海贼王”这部动画片,不仅仅是因为其中的人物个个性格鲜明,剧情跌宕起伏扣人心弦,各种耍宝搞笑,还感觉到这个团队很像理想中的敏捷软件团队. 作为一直带团队的我,感觉“海贼王”这个动画片给了我很 ...
- Golang友团无闻Go语言Web基础视频教程
教程内容:GO语言资料Golang友团无闻Go语言编程基础Golang友团无闻Go语言Web基础教程 Go语言Web基础教程列表:[Go Web基础]12Go Web 扩展学习.mp4[Go Web基 ...
- 【深度分享】千团大战:看今天商业WiFi乱局及其破解之道
不知道还有没有人记得起始于2010年的千团大战.从2010年初开始,第一家团购网站上线以来,到2011年底,团购网站的数量超过了5000家.当时就有很多媒体预言,2013年,团购的泡沫就将褪去,将有9 ...
- 猿团YTFCloud生态系统,全面服务创业者
9月15日,YTFCloud已正式开启了内测. 创业者翘首以待的YTFCloud,虽然让部分创业者感受到了它的神奇,但对于更多暂时无法尝试的创业者来说,它依然有一层神秘的面纱. 今天小编就来带你近距离 ...
- 猿团YTFCloud--5分钟自制APP,开发从未如此简单
9月15日,YTFCloud将正式开启内测, 这意味着猿团YTF框架产品线全面升级.同时,公测过后,YTFCloud的APP线上DIY服务将面向所有用户,让人人都能成为APP“开发商”. 什么是YTF ...
- ecshop 团购点击价格变动
前提:价格阶梯只能设置一级 需要用到: jquery,transport.js(transport_jquery.js),Ajax.call html页面 js代码,还需要插入jquery,trans ...
- iOS开发——UI进阶篇(二)自定义等高cell,xib自定义等高的cell,Autolayout布局子控件,团购案例
一.纯代码自定义等高cell 首先创建一个继承UITableViewCell的类@interface XMGTgCell : UITableViewCell在该类中依次做一下操作1.添加子控件 - ( ...
随机推荐
- guava常用操作
Jack47 我思故我在 Google Java编程库Guava介绍 本系列想介绍下Java下开源的优秀编程库--Guava[ˈgwɑːvə].它包含了Google在Java项目中使用一些核心库,包含 ...
- ubuntu14上安装ros教程
安装ROS 官方的安装教程地址 http://wiki.ros.org/cn/jade/Installation/Ubuntu 建议安装indigo版的 下面的教程是安装jade版的 配置Ubuntu ...
- toodifficult 题解
名字听起来十分厉害啊...一道lzz的提交答案题. 提答题,我们看看题目,给出一个解密程序,叫你加密. 每个点有一个加密的sample和一些要加密的文本. 从题目中我们可以得到一些信息: 加密后一般为 ...
- PhpExcel中文帮助手册|PhpExcel使用方法
下面是总结的几个使用方法 include 'PHPExcel.php'; include 'PHPExcel/Writer/Excel2007.php'; //或者include 'PHPExcel/ ...
- C语言:void指针
使用前必须进行强制类型转换 #include <stdio.h> void test(const void *p); int main(){ ; int *p = &i; puts ...
- JS给文本框赋值后,在页面后台取不到文本框值的解决方法
转自:http://www.cnblogs.com/qiaohd/archive/2012/03/23/2413660.html (ReadOnly.disabled 都有可能造成取值取不到) 开发一 ...
- Linux 网络编程详解二(socket创建流程、多进程版)
netstat -na | grep " --查看TCP/IP协议连接状态 //socket编程提高版--服务器 #include <stdio.h> #include < ...
- rpc框架之 thrift 学习 1 - 安装 及 hello world
thrift是一个facebook开源的高效RPC框架,其主要特点是跨语言及二进制高效传输(当然,除了二进制,也支持json等常用序列化机制),官网地址:http://thrift.apache.or ...
- 基于VirtualBox安装Ubuntu图文教程
基于VirtualBox虚拟机安装Ubuntu图文教程 一. 下载安装VirtualBox 官网下载VirtualBox,目前版本:VirtualBox 5.1.8 for Windows hosts ...
- python网络编程学习《一》
最近,刚实习完,很喜欢实验楼,但是自己的方向仍然不能确定,自己觉得可选择的空间很大,尽管已经是大四的人了,想到别人都在忙着买职业装,买高跟鞋面试,学习化妆什么的,看看自己,反而开始慢慢关注运动,食疗以 ...