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 ...
随机推荐
- R vs Python,数据分析中谁与争锋?
R和Python两者谁更适合数据分析领域?在某些特定情况下谁会更有优势?还是一个天生在各方面都比另一个更好? 当我们想要选择一种编程语言进行数据分析时,相信大多数人都会想到R和Python——但是从这 ...
- python 用Threading创建多线程
#-*-coding:utf-8-*- '''python标准库提供了两个多线程模块,分别为thread和threading, 其中thread模块是低级模块,threading是高级模块,对thre ...
- VirtualBox安装Centos后实现文件夹共享
不同虚拟机中的系统和windows之间实现文件共享方式也不一样,在VMWare虚拟机请参考链接:http://www.cnblogs.com/vincentfu/p/5402666.html 进入主题 ...
- 变量&常量
变量:variables 存储数据,以被后面的程序调用,可以看作是:装信息的容器: 变量的作用:(1)标记数据(2)存储数据 变量定义规范1.声明变量:定义变量 name = "Mr H ...
- Kafka 0.8翻译官网精华.md
1主要的设计元素 Kafka之所以和其它绝大多数信息系统不同,是因为下面这几个为数不多的比较重要的设计决策: Kafka在设计之时为就将持久化消息作为通常的使用情况进行了考虑. 主要的设计约束是吞吐量 ...
- SQL记录-PLSQL记录
PL/SQL记录 PL/SQL记录就是可以容纳不同类型的数据项的数据结构.记录由不同字段,类似于数据库表的行. 例如,要保留跟踪图书馆中的书籍.可能要跟踪有关每本书下面的属性类似:标题,作者,主题 ...
- 原始套接字-自定义IP首部和TCP首部
/* ===================================================================================== * * Filenam ...
- Lua程序设计(二)面向对象概念介绍
----------------------------------------------------------- Lua面向对象3 local smartMan = { name = " ...
- javascript完美拖拽的实现
直接上代码: HTML代码: <!DOCTYPE HTML> <html lang="en-US"> <head> <meta chars ...
- Sublime Text 2 破解 on Mac
用Sublime Text 2自己打开自己的二进制文件:Sublime Text 2/Contents/MacOS/Sublime Text 2 搜索所有3342 3032 都替换成3242 3032 ...