题目链接:http://poj.org/problem?id=1129

思路:根据图的四色定理,最多四种颜色就能满足题意,使得相邻的两部分颜色不同。而最多又只有26个点,因此直接dfs即可。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; bool map[][];
int mark[];
char str[];
int n,ans; bool Judge(int x,int color)
{
for(int i=;i<n;i++){
if(i!=x&&map[x][i]&&mark[i]==color)
return ;
}
return ;
} void dfs(int pos)
{
if(pos==n){
ans=min(ans,*max_element(mark,mark+n));
return ;
}
for(int i=pos;i<n;i++){
for(int j=;j<=;j++){
if(Judge(i,j)){
mark[i]=j;
dfs(i+);
}
}
}
} int main()
{
while(~scanf("%d",&n)&&n){
memset(map,false,sizeof(map));
for(int i=;i<n;i++){
scanf("%s",str);
for(int j=;j<strlen(str);j++){
map[i][str[j]-'A']=true;
map[str[j]-'A'][i]=true;
}
}
memset(mark,,sizeof(mark));
ans=;
mark[]=;
dfs();
if(ans==){
printf("1 channel needed.\n");
}else
printf("%d channels needed.\n",ans);
}
return ;
}

最新文章

  1. EasyUI中那些不容易被发现的坑——EasyUI重复请求2次的问题
  2. DoTween 应用设置
  3. python PIL Image模块
  4. ubuntu下crontab编辑方法的设定
  5. 使用.NET FrameWork获取CPU,内存使用率以及磁盘空间
  6. SOA_环境安装系列2_Oracle RCU安装和环境搭建(案例)
  7. codeforces 590C C. Three States(bfs+连通块之间的最短距离)
  8. IOS 中得runloop 详细解释
  9. Laravel5中集成Jasig cas统一认证系统
  10. 设计模式之 - 外观模式 (Facade design pattern)
  11. Hibernate入门(三)
  12. IIS最小配置
  13. 基于WebSocket 私聊、ws_session、httpsession
  14. 泛微云桥e-birdge之金蝶云之家集成配置手册
  15. 白话js this指向问题
  16. hdfs平衡分布
  17. [Cpp primer] Library string Type
  18. python:while 语句的使用方法
  19. react.js学习之路三
  20. ant-design-pro使用服务器数据接口代理配置

热门文章

  1. 算法笔记_069:Floyd算法简单介绍(Java)
  2. webDriver API——第15部分Expected conditions Support
  3. JavaScript | window浏览器对象模型
  4. Image Based Lighting In UE3
  5. IOS研究之App转让流程须知具体介绍
  6. HTML5&amp;amp;CSS3初学者指南
  7. 何为优秀的机器学习特征 zz
  8. Bash编程的难点
  9. C#反射取数组单个元素的类型
  10. hbase replication原理分析