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

开始没读懂题,看discuss的做法,都是循环枚举的,很麻烦。然后我就决定dfs,调试了半天终于0ms A了。

 #include <stdio.h>
#include <string.h>
bool graph[][], vis[][];
int n, ans; void calc()
{
int cnt = ;
for(int i = ; i < ; i++)
{
for(int j = ; j < n; j++)
{
if(vis[j][i])
{
cnt++;
break;
}
}
}
if(cnt < ans)ans = cnt;
} void dfs(int x)
{
if(x >= n)
{
calc();
return;
} for(int i = ; i < ; i++)
{
bool ok = ;
for(int j = ; j < n; j++)
{
if((graph[j][x] && vis[j][i]) || (graph[x][j] && vis[j][i]))
{
ok = ;
break;
}
}
if(ok)
{
vis[x][i] = ;
dfs(x+);
vis[x][i] = ;
}
}
} int main()
{
char s[];
while(scanf("%d", &n) != EOF && n)
{
ans = 0x3f3f3f3f;
memset(graph, , sizeof(graph));
memset(vis, , sizeof(vis));
for(int i = ; i < n; i++)
{
scanf("%s", s);
for(int j = ; s[j]; j++)
{
graph[i][s[j]-'A'] = ;
}
}
vis[][] = ;
dfs();
if(ans == )
printf("1 channel needed.\n");
else printf("%d channels needed.\n", ans);
}
return ;
}

POJ 1129 Channel Allocation 四色定理dfs的更多相关文章

  1. POJ 1129 Channel Allocation(DFS)

    Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13173   Accepted: 67 ...

  2. 迭代加深搜索 POJ 1129 Channel Allocation

    POJ 1129 Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14191   Acc ...

  3. POJ 1129 Channel Allocation DFS 回溯

    Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 15546   Accepted: 78 ...

  4. poj 1129 Channel Allocation ( dfs )

    题目:http://poj.org/problem?id=1129 题意:求最小m,使平面图能染成m色,相邻两块不同色由四色定理可知顶点最多需要4种颜色即可.我们于是从1开始试到3即可. #inclu ...

  5. poj 1129 Channel Allocation(图着色,DFS)

    题意: N个中继站,相邻的中继站频道不得相同,问最少需要几个频道. 输入输出: Sample Input 2 A: B: 4 A:BC B:ACD C:ABD D:BC 4 A:BCD B:ACD C ...

  6. poj 1129 Channel Allocation

    http://poj.org/problem?id=1129 import java.util.*; import java.math.*; public class Main { public st ...

  7. Channel Allocation(四色定理 dfs)

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10897   Accepted: 5594 Description When ...

  8. POJ 1129:Channel Allocation 四色定理+暴力搜索

    Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13357   Accepted: 68 ...

  9. Channel Allocation(DFS)

    Channel Allocation Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other) ...

随机推荐

  1. Linux环境进程间通信

    http://www.ibm.com/developerworks/cn/linux/l-ipc/part2/index2.html http://bbs.chinaunix.net/forum.ph ...

  2. Mac上安装boost开放环境

    方法一: 去Macports官网的下载页面(https://distfiles.macports.org/MacPorts/)下载对用Mac系统的pkg文件,下载完成之后,双击,一路[下一步],到安装 ...

  3. SVN修改已提交版本的日志

    在工作中一直是使用svn进行项目的版本控制的,有时候由于提交匆忙,或是忘了添加Log,或是Log内容写的有错误.今日遇到此类情况,想要在查看项目的日志时添加log或是修改log内容,遇到如下错误:Re ...

  4. oracle数据库没有监听服务与实例服务(OracleServicesXX)的解决方法

    不知道为什么,可能是因为更新系统的原因,过了一段时间,想打开oracle服务,发现居然没有任何oracle有关的服务了,但以前的数据库文件什么的都在,心想肯定是可以复原的,应该只是注册表的问题罢了.在 ...

  5. MySQL解压版安装配置详解

    MySQL解压版安装起来比较简单,步骤相对较少.下面我们就来详细介绍一下如何在windows操作系统上安装解压班的MySQL. 1.下载解压版MySQL,地址:http://downloads.mys ...

  6. C# ado.net 使用 row_number over() 简单的分页示例

    /// <summary> /// 获取Paging列表 /// </summary> public List<HousesAgentEntity> GetPage ...

  7. .Net之美读书系列(一):委托与事件

    开启新的读书之旅,这次读的书为<.Net之美:.Net关键技术深入解析>. 我是选择性阅读的,把一些自己觉得容易忘记的,或者比较重要的知识点记录下来,以便以后能方便呢查阅. 尊重书本原作者 ...

  8. Android开发5大布局方式详解

    Android中常用的5大布局方式有以下几种: 线性布局(LinearLayout):按照垂直或者水平方向布局的组件. 帧布局(FrameLayout):组件从屏幕左上方布局组件. 表格布局(Tabl ...

  9. win向linux传文件

    使用pscp.exe即可. 下载pscp.exe(http://pan.baidu.com/s/1jG6zmx4) 复制到windows/system32目录下即可. 然后可在cmd命令行下使用psc ...

  10. ios 阻止GDB依附

    GDB,IDE是大多数hackers的首选,阻止GDB依附到应用的常规办法是: . #import <sys/ptrace.h> . . int main(int argc, charch ...