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 ...
随机推荐
- c++ 自动对象
转自: https://www.cnblogs.com/geloutingyu/p/8034904.html 1.自动对象默认情况下,局部变量的生命期局限于所在函数的每次执行期间.只有当定义它的函数被 ...
- window安装设置
https://jingyan.baidu.com/article/73c3ce28ed7d92e50243d96c.html
- Java数据结构和算法(三)顺序存储的树结构
Java数据结构和算法(三)顺序存储的树结构 二叉树也可以用数组存储,可以和完全二叉树的节点一一对应. 一.树的遍历 // 二叉树保存在数组中 int[] data; public void preO ...
- 模型参数_grid
from sklearn import datasetsfrom sklearn.model_selection import train_test_splitfrom sklearn.preproc ...
- 客户端、服务器端中JSON字符串与对象的转换
客户端: 字符串转为对象:$.parseJSON(json); 对象转为字符串:JSON.stringify(_pasteDataItem) 服务器端(c#): 对象: [DataContract(N ...
- 2018.06.30 cdq分治
#cdq分治 ##一种奇妙的分治方法 优点:可以顶替复杂的高级数据结构:常数比较小. 缺点:必须离线操作. CDQ分治的基本思想十分简单.如下: 我们要解决一系列问题,包含修改和查询操作,我们将这些问 ...
- 命令行生成war包
1.找到自己的代码位置 2.进入cmd界面 3.进入对应的目录 4.执行命令 5.就会开始自动打包 6.在文件夹下生成对应的war包
- 17)maven-surefire-plugin
http://maven.apache.org/surefire/maven-surefire-plugin/ Goals Overview The Surefire Plugin has only ...
- 14)settings.xml
1. User Level. ${user.home}/.m2/settings.xml 2. Global Level. ${maven.home}/conf/settings.xml <se ...
- js基础学习笔记(四)
4.1 什么是数组 我们知道变量用来存储数据,一个变量只能存储一个内容,存储多个值时,就需要用到数组. 数组是一个值的集合,每个值都有一个索引号,从0开始,每个索引都有一个相应的值,根据需要添加更多数 ...