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 ...
随机推荐
- Spring点滴十:Spring自动装配(Autowire)
在基于XML配置元数据,在bean的配置信息中我们可以使用<constructor-arg/>和<property/>属性来实现Spring的依赖注入.Spring 容器也可以 ...
- 2019.2.28&2019.3.1 考试
因为没A/改几道题,就一起写了 题目在LOJ上都能找到 2019.2.28 100+20+12 前两个小时一直在睡觉+想题也没思路,我太菜了 T1 洗衣服 分开处理出洗衣服和烘干的时间,然后一边正着排 ...
- 21天实战caffe笔记_第三天
1 深度学习工具汇总 (1) caffe : 由BVLC开发的基于C++/CUDA/Python实现的卷积神经网络,提供了面向命令行.Matlab和Python的绑定接口.特性如下: A 实现了前馈 ...
- debian8.4 ibus中文输入法
安装IBus: # apt-get install ibus ibus-sunpinyin ibus-table-wubi 导入输入法: 在Activities->Applications-&g ...
- 「Vue」vue cli3项目打包为APP方法及坑点
1.执行npm run build之后生成dist文件夹 2.打开HBuilderX新建一个APP项目 3.把dist文件夹里的所有文件拷贝替换到APP文件夹下 4.打开manifest.json文件 ...
- IDE和SDK
像我这种不是专科班出来的,真的很多概念都不太清楚,今天来说说IDE和SDK 简单的来说: IDE(集成开发环境 Integrated Development Environment) 就是我们编写代码 ...
- vue中assets文件夹与static文件夹的区别
1.如果这些产品图片文件“万年不变”,放在 /static 目录里,(不需要使用require将这些图片作为模块来引用) var products = [{ img: '/static/img/pro ...
- CSS 设置网页中选中文字的背景色
在样式文件中增加如下代码: ::selection { background: hsla(5, 92%, 76%, 0.8); color: #fff;}
- poj 3686 Priest John's Busiest Day
http://poj.org/problem?id=3683 2-sat 问题判定,输出一组可行解 http://www.cnblogs.com/TheRoadToTheGold/p/8436948. ...
- js 语法高亮插件之 Prism.js
之前也介绍过几款语法高亮插件<为博客园选择一个小巧霸气的语法高亮插件>以及关于他们的综合性能<再议 语法高亮插件的选择>.今天在小影志博客看到<使用 Prism.js 实 ...