POJ 1129
#include<iostream>
#include<stdio.h>
#include<string>
#define MAXN 60
using namespace std;
int max_clique(int n, int * * mat, int *ret) ;
int main()
{
//freopen("acm.acm","r",stdin);
int i;
int ans;
int j;
string s;
int num;
int * * _m;
int * ret;
while(cin>>num)
{
if(num == )
break;
_m = new int * [num];
ret = new int[num];
for(i = ; i < num; ++ i)
{
_m[i] = new int[num];
memset(_m[i],,sizeof(int)*num);
}
//for(i = 0; i < num; ++ i)
// for(j = 0; j < num; ++ j)
// cout<<_m[i][j]<<" ";
for(i = ; i < num; ++ i)
{
cin>>s;
if(s.length() == )
continue;
else
{
for(j = ; j < s.length(); ++ j)
{
_m[s[] - 'A'][s[j] - 'A'] = ;
}
}
}
ans = max_clique(num,_m,ret);
cout<<ans;
if(ans == )
cout<<" channel needed."<<endl;
else
cout<<" channels needed."<<endl;
delete [] _m;
delete ret;
}
} void clique(int n, int* u, int * * mat, int size, int& max, int& bb, int * res, int* rr, int* c) {
int i, j, vn, v[MAXN];
if (n) {
if (size + c[u[]] <= max) return;
for (i = ; i < n + size - max && i < n; ++ i) {
for (j = i + , vn = ; j < n; ++ j)
if (mat[u[i]][u[j]])
v[vn ++] = u[j];
rr[size] = u[i];
clique(vn, v, mat, size + , max, bb, res, rr, c);
if (bb) return;
}
} else if (size > max) {
max = size;
for (i = ; i < size; ++ i)
res[i] = rr[i];
bb = ;
}
} int max_clique(int n, int * *mat, int * ret) {
int max = , bb, c[MAXN], i, j;
int vn, v[MAXN], rr[MAXN];
for (c[i = n - ] = ; i >= ; -- i) {
for (vn = , j = i + ; j < n; ++ j)
if (mat[i][j])
v[vn ++] = j;
bb = ;
rr[] = i;
clique(vn, v, mat, , max, bb, ret, rr, c);
c[i] = max;
}
return max;
}
关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。

技术网站地址: vmfor.com
POJ 1129的更多相关文章
- 迭代加深搜索 POJ 1129 Channel Allocation
POJ 1129 Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14191 Acc ...
- poj 1129 Channel Allocation ( dfs )
题目:http://poj.org/problem?id=1129 题意:求最小m,使平面图能染成m色,相邻两块不同色由四色定理可知顶点最多需要4种颜色即可.我们于是从1开始试到3即可. #inclu ...
- POJ 1129 Channel Allocation 四色定理dfs
题目: http://poj.org/problem?id=1129 开始没读懂题,看discuss的做法,都是循环枚举的,很麻烦.然后我就决定dfs,调试了半天终于0ms A了. #include ...
- poj 1129 Channel Allocation
http://poj.org/problem?id=1129 import java.util.*; import java.math.*; public class Main { public st ...
- poj 1129(dfs+图的四色定理)
题目链接:http://poj.org/problem?id=1129 思路:根据图的四色定理,最多四种颜色就能满足题意,使得相邻的两部分颜色不同.而最多又只有26个点,因此直接dfs即可. #inc ...
- 四色定理+dfs(poj 1129)
题目:Channel Allocation 题意:要求A:BCD,A与B,C,D都不相同,求不同的值,典型的四色定理: #include <iostream> #include <a ...
- Channel Allocation (poj 1129 dfs)
Language: Default Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12 ...
- poj 1129 搜索
Channel Allocation Time Limit: 1000 MS Memory Limit: 10000 KB 64-bit integer IO format: %I64d , %I64 ...
- POJ 1129 Channel Allocation(DFS)
Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13173 Accepted: 67 ...
随机推荐
- 2018.10.19 NOIP模拟 比特战争(kruskal)
传送门 考完发现是sbsbsb题啊. 直接考虑优化状压的转移. 可以证明最优解一定在求最小生成树的时候取得. 因此再最小生成树时维护一下连通块的最值统计答案就行了. 代码
- 2018.09.23 codeforces 1053A. In Search of an Easy Problem(gcd)
传送门 今天的签到题. 有一个很显然的结论,gcd(n∗m,k)≤2gcd(n*m,k)\le 2gcd(n∗m,k)≤2. 本蒟蒻是用的行列式求三角形面积证明的. 如果满足这个条件,就可以直接构造出 ...
- arduino IO口
AVR单片机的每组I/O口都配备有三个8位寄存器,分别是:方向控制寄存器DDRx.数据寄存器PORTx.输入引脚寄存器PINx(x=A/B/C/D).I/O口的工作方式和表现特征由这三个I/O寄存器控 ...
- VHDL的库
STD_LOGIC_ARITH 扩展了UNSIGNED.SIGNED.SMALL_INT(短整型)三个数据类型,并定义了相关的算术运算和转换函数. --======================== ...
- 13.A={1,2,3,5}和为10的问题
题目:集合A={1,2,3,5},从中任取几个数相加等于10,并打印各得哪几个数?补充参照:http://www.cnblogs.com/tinaluo/p/5294341.html上午弄明白了幂集的 ...
- 好久不发帖,转一下公司技术美术独立完成的U3D模拟暗黑泰瑞尔翅膀物理运动效果
想入公司倍培养成为优秀的技术型美术,欢迎call我! Max制作翅膀模型部分 新建一个片面,模型给一些段数,赋予一张左右二方连续贴图. 加个FFD 4*4*4,并稍微拉出一点弧度. 将头尾的Alpha ...
- Git小技巧:VIM中如何填写注释信息
使用Git命令行工具的时候,经常一不小心就进入VIM界面,例如git commit没有填写任何描述信息.对于习惯了Windows可视化操作界面的用户,可能一下子会觉得无所适从,只能在键盘上一顿短按.下 ...
- INDEX--创建索引和删除索引时的SCH_M锁
最近有一个困惑,生产服务器上有一表索引建得乱七八糟,经过整理后需要新建几个索引,再删除几个索引,建立索引时使用联机(ONLINE=ON)创建,查看下服务器负载(磁盘和CPU压力均比较低的情况)后就选择 ...
- Asp.Net 跨域,Asp.Net MVC 跨域,Session共享,CORS,Asp.Net CORS,Asp.Net MVC CORS,MVC CORS
比如 http://www.test.com 和 http://m.test.com 一.简单粗暴的方法 Web.Config <system.web> <!--其他配置 省略……- ...
- 使用ABP框架踩过的坑系列1
企业级(例如ERP)应用, 一遍一遍的在重复:认证.验证.异常处理.日志.国际化和本地化.数据库连接管理.配置管理. 审计记录等,同时.NET有很多最佳实践:分层.模块化.DDD领域驱动.DI ...