Channel Allocation HDU1373
染色问题:相邻不能染同一种颜色
最少需要的颜色的数量=最大团点的数量
#include<bits/stdc++.h>
using namespace std; #define N 27 int n;
int mp[N][N];
int ans;
int alt[N][N];
int Max[N]; bool dfs(int cur,int tot)//cur是s1集合的个数
{
if(==cur)
{
if(tot>ans)
{
ans=tot;return true;
}
return false;
} for(int i=;i<cur;i++)
{
if( tot+cur-i<=ans )return false;
int u=alt[tot][i];
if( Max[u]+tot<=ans )return false;
int next=;
for(int j=i+;j<cur;j++)
if(mp[u][ alt[tot][j] ])alt[tot+][next++]=alt[tot][j];
if(dfs(next,tot+)) return ;
}
return ;
} int maxclique(void)
{
ans=;
memset(Max,,sizeof(Max));
for(int i=n-;i>=;i--)
{
int cur=;
for(int j=i+;j<n;j++)if(mp[i][j])alt[][cur++]=j;//1为s1集合
dfs(cur,);
Max[i]=ans;
}
return ans;
} int main()
{ char s[]; while(scanf("%d",&n),n)
{
memset(mp,,sizeof (mp));
for(int i=;i<n;i++)
{
scanf("%s",s);
for(int j=;s[j];j++)
mp[i][ s[j]-'A' ]=mp[ s[j]-'A' ][i]=;
}
int ans=maxclique();
if(ans==) printf("1 channel needed.\n");
else printf("%d channels needed.\n", ans);
}
return ;
}
Channel Allocation HDU1373的更多相关文章
- 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 1129 Channel Allocation(DFS)
Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13173 Accepted: 67 ...
- 快速切题 poj1129 Channel Allocation
Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12334 Accepted: 63 ...
- POJ 1129 Channel Allocation DFS 回溯
Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 15546 Accepted: 78 ...
随机推荐
- 【BZOJ1227】[SDOI2009]虔诚的墓主人(线段树)
[BZOJ1227][SDOI2009]虔诚的墓主人(线段树) 题面 BZOJ 洛谷 题解 显然发现答案就是对于每一个空位置,考虑上下左右各有多少棵树,然后就是这四个方向上树的数量中选\(K\)棵出来 ...
- 界面编程之QT的线程20180731
/*******************************************************************************************/ 一.为什么需 ...
- linux basic ------ shell
一般习惯把 shell 脚本语言和 shell 解释器统称为 shell,用 shell 脚本语言编写的程序简称脚本. shell 解释器 是用 c 语言写一个应用程序,它是用户使用 Unix / L ...
- Hadoop Yarn源码 - day2
接着昨天的继续看hadoop-yarn-api,昨天看了api package下的4个协议,今天来看下con package下的代码 conf目录下的内容比较少,就4个文件分别是Configurati ...
- SpringBoot Logback日志配置
Logback的配置介绍: 1.Logger.appender及layout Logger作为日志的记录器,把它关联到应用的对应的context上后,主要用于存放日志对象,也可以定义日志类型.级别. ...
- bzoj千题计划284:bzoj2882: 工艺
http://www.lydsy.com/JudgeOnline/problem.php?id=2882 将串S复制一遍变成SS 对SS构建后缀自动机,在上面走标号最小的边len(S)步,即可得最小循 ...
- bzoj千题计划201:bzoj1820: [JSOI2010]Express Service 快递服务
http://www.lydsy.com/JudgeOnline/problem.php?id=1820 很容易想到dp[i][a][b][c] 到第i个收件地点,三个司机分别在a,b,c 收件地点的 ...
- [转载]DOMContentLoaded与interactive
http://www.cnblogs.com/muxrwc/archive/2011/01/13/1934379.html ie中inline script执行时竟然第一次进入页面,doc.ready ...
- 将网页设置为允许 XMLHttpRequest 跨域访问
在非IE下,使用XMLHttpRequest 不能跨域访问, 除非要访问的网页设置为允许跨域访问. 将网页设置为允许跨域访问的方法如下: Java Response.AddHeader("A ...
- AngularJS入门基础——过滤器
在HTML中的模板绑定符号{{ }}内通过 | 符号来调用过滤器 {{ name | uppercase }} 以HTML的形式使用过滤器时,如果需要传递参数给过滤器,只要在过滤器名字后面加冒号即 ...