题目: 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. AFNetworking源码分析

    来源:zongmumask 链接:http://www.jianshu.com/p/8eac5b1975de 简述 在iOS开发中,与直接使用苹果框架中提供的NSURLConnection或NSURL ...

  2. 考试必备神器-真题园手机客户端Android版1.1正式上线啦,欢迎大家下载使用!

    真题园-考试必备神器,爱学习,找真题! 真题园-考试必备神器,爱学习,找真题!1.真题园android客户端1.1版全新发布上线.2.最新教育资讯实时更新,了解行业动态新闻.3.最新最全的真题大全,最 ...

  3. Android(java)学习笔记164:Relativelayout相对布局案例

    我们看看案例代码,自己心领神会: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout ...

  4. android中实现简单的播放

    MediaPlayer mediaPlayer1; mediaPlayer1 = MediaPlayer.create(getBaseContext(), R.raw.ic_yanyuan); med ...

  5. Javascript,闭包

    js变量的调用 一.全局变量函数调用 var n = 99; function f1() { alert(n); } f1();//99 在函数外部定义的变量,再函数中可以被调用,因为变量n,与f1在 ...

  6. javascript-01

    1.JavaScript:浏览器脚本语言 2.JavaScript的作用  |-1.进行前端验证  |-2.实现页面的动态效果 3.JavaScript的特点  |-1.和java没有任何关系,官方标 ...

  7. VS2013+SVN管理

    进入新公司,大部分员工使用的是VS2013 ,所以搜集了下支持VS2013的一些SVN工具,现在发布到园子,供大家使用. CodeMaid插件,能够很好的格式化代码,强迫症的最爱: TortoiseS ...

  8. MVC小系列(十一)【Html.BeginForm与Ajax.BeginForm】

    Html.BeginForm与Ajax.BeginForm都是mvc的表单元素,前者是普通的表单提交,而后者是支持异步的表单提交,直接用mvc自带的Ajax.BeginForm就可以很容易完成一个异步 ...

  9. 项目由Windows2003 迁移到Windows 2008 过程,报 JS错误

    这两天在做服务器迁移,遇到了一些小的问题,现在做个粗略的记录 原服务器环境:Windows 2003 现服务器环境:Windows 2008 其中SSB项目在迁移部署后发现,报 JS的错误. 我在想除 ...

  10. 直播类送礼动画<豪华礼物+小礼物>

    直播类送礼动画<豪华礼物+小礼物>:代码会持续更新,现直播的app里内有太多的动画,由于时间关系不能一次共享所有动画聘为,这次先共享几个比较火爆的动画. 支持真机和模拟器上运行,最低支持i ...