hdoj1373 Channel Allocation(极大团)
题意是有若干个接收器,给出每个接收器的相邻接收器。相邻的接收器不能使用同一信号频道。问所需要的信号频道数。
求该无向图的极大团。
#include<iostream>
#include<cstring>
#include<string>
#define maxn 30
using namespace std;
int stack[maxn],map[maxn][maxn];
int n,cn,bestn;
void dfs(int x){
if (x>n){
bestn=max(cn,bestn);
return ;
}
int flag=;
for (int i=;i<cn;i++){
if (!map[stack[i]][x]){
flag=;
break;
}
}
if (flag){
stack[cn++]=x;
dfs(x+);
cn--;
}
if (cn+n-x>bestn){
dfs(x+);
}
}
int main(){
string S;
while (cin >> n && n){
memset(map,,sizeof(map));
for (int id=;id<n;id++){
cin >> S;
int pre=S[]-'A';
int len=S.length();
for (int i=;i<len;i++){
int res=S[i]-'A';
map[pre][res]=map[res][pre]=;
}
}
cn=bestn=;
memset(stack,,sizeof(stack));
dfs();
if (bestn==) cout << "1 channel needed.\n";
else cout << bestn << " channels needed.\n";
}
return ;
}
hdoj1373 Channel Allocation(极大团)的更多相关文章
- poj1129 Channel Allocation
Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14361 Accepted: 73 ...
- 迭代加深搜索 POJ 1129 Channel Allocation
POJ 1129 Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14191 Acc ...
- Channel Allocation
Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13231 Accepted: 6774 D ...
- poj1129 Channel Allocation(染色问题)
题目链接:poj1129 Channel Allocation 题意:要求相邻中继器必须使用不同的频道,求需要使用的频道的最少数目. 题解:就是求图的色数,这里采用求图的色数的近似有效算法——顺序着色 ...
- Channel Allocation (poj 1129 dfs)
Language: Default Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12 ...
- Channel Allocation(DFS)
Channel Allocation Time Limit : 2000/1000ms (Java/Other) Memory Limit : 20000/10000K (Java/Other) ...
- POJ 2989 All Friends 极大团计数
POJ 2989 题意:给定一个无向图(节点数小于128)求极大团(不包含在更大的团中)的总数. 对最大团,极大团不熟悉的,建议先阅读最大团搜索问题 ZOJ 1492 再来看本题. 本题数据有限,可以 ...
- All Friends 极大团
搞懂了什么是团 什么是极大团 什么是最大团 极大团就是 不是任何团的真子集 最大团就是点数最多的极大团 这题就是求极大团的个数 用bk算法 #include <iostream> ...
- POJ 1129 Channel Allocation(DFS)
Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13173 Accepted: 67 ...
随机推荐
- Linux 添加硬盘
一.简介 本文介绍为Linux 添加硬盘的基本方法,同时适用于为虚拟机添加硬盘的情况. 二.添加小于2T的硬盘 1)分区 fdisk /dev/hda 2)建立文件系统 3)设置开机自动挂载磁盘 ...
- 史上最全的Android开发学习教程集锦【初学者】
根据Google的报告,截止2017年5月为止,Android活跃用户已超过20亿,并还在持续增长中.Android系统在几个主要的市场上已超过了iOS系统,特别是在美国,欧洲和日本,然而苹果确实在中 ...
- vue的过滤器
Vue.Js 提供了强大的过滤器API,能够对数据进行各种过滤处理,返回需要的结果 vue的过滤器一般在JavaScript 表达式的尾部,由“|”符号指示: 过滤器可以让我们的代码更加优美,一般可以 ...
- Perl注释文本的高亮显示规则
sub help{ print <<EndOfUsage;\e[1;37mHELP :1. Usage : perl $0 input output 2. Function : tran ...
- pytest 入门及运行
关于pytest的入门教程,官网及网上已经很多了,那再多一点也无所谓吧!OK,进入正题~ 下面是一个测试用例,test_one.py def test_passing(): assert (1, ...
- 解决 multiple definition of
总结了解决multiple definition of的方法: 问题原因: 当多个文件包含同一个头文件时,并且你的.H里面没有加上条件编译#ifndef TEST_H#define TEST_H ...
- Oracle SQL性能优化技巧大总结
http://wenku.baidu.com/link?url=liS0_3fAyX2uXF5MAEQxMOj3YIY4UCcQM4gPfPzHfFcHBXuJTE8rANrwu6GXwdzbmvdV ...
- [leetcode] 14. Climbing Stairs
这道题leetcode上面写着是DP问题,问题是我一开始写了个简单的递归结果直接超时,所以没办法只好拿迭代来做了.题目如下: You are climbing a stair case. It tak ...
- SQL SERVER 2014--学习笔记1
--======================================================= 在SQL SERVER 2014中,最吸引眼球的就是内存表和本地编译存储过程,在MS ...
- hadoop2.6 上hive运行 报“native-lzo library not available”异常处理
环境:Hadoop 2.6.0 + hive-0.14.0 问题出现的背景:在hive中建表 (建表语句如下),并且表的字段中有Map,Set,Collection等集合类型. CREATE EXT ...