题目: 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. nginx模块编程之获取客户ip及端口号

    ngx_request_t结构体中有一个connection定义,该定义指向一个ngx_connection_t的结构体: 结构体定义如下: struct ngx_connection_s { voi ...

  2. js获取浏览器类型

    function add(){ var userAgent = navigator.userAgent, rMsie = /(msie\s|trident.*rv:)([\w.]+)/, rFiref ...

  3. Android_Intent_passObject

    方法4. 把基本的数据类型封装到一个对象中,然后通过intent传递该对象需要考虑对Person对象进行序列化 MainActivity: package com.example.day06_acti ...

  4. 转:oracle ebs po模块一揽子采购协议小结

    转自:http://yedward.net/?id=193 oracle ebs po模块一揽子采购协议小结 本文总结oracle ebs采购订单(po)模块一揽子采购协议的相关知识,总结如下: 1. ...

  5. 爬虫神器XPath,程序员带你免费获取周星驰等明星热门电影

    本教程由"做全栈攻城狮"原创首发,本人大学生一枚平时还需要上课,但尽量每日更新文章教程.一方面把我所习得的知识分享出来,希望能对初学者有所帮助.另一方面总结自己所学,以备以后查看. ...

  6. [转]SharePoint 2010/2013 使用Javascript来判断权限的三种方法

    本文讲述SharePoint 2010/2013 使用Javascript来判断权限的三种方法的实现方式及其优缺点. 1. 根据用户所在的SharePoint组(比如用户在Leader 组才可以使用审 ...

  7. VS 2013 Chrome PPAPI 开发环境

    当前系统版本为 Windows 8.1 x64, Chrome 版本为 50.0 1. 准备工作 下载并安装 Python https://www.python.org/download/ * 必须使 ...

  8. MVC中HtmlHelper用法大全参考

    MVC中HtmlHelper用法大全参考 解析MVC中HtmlHelper控件7个大类中各个控件的主要使用方法(1) 2012-02-27 16:25 HtmlHelper类在命令System.Web ...

  9. JQuery Jplayer play无效的问题

    最近折腾个H5. 用到Jplayer, 用着不错,至少兼容性强一些. 但是安卓这辆公共汽车型号实在太多.不小心上了一辆奇葩的就容易震到生活不能自理. 我在一台手机上的五六个浏览器上测试,都可以. 把该 ...

  10. Android网络对讲机的实现

    上个星期公司给出了一个项目需求,做一个基于socket通讯协议的网络对讲机.于是在项目开始前计划了一下基本的实现流程. 1.从手机麦中采集音频数据:2.将PCM音频数据编码压缩:3.将压缩好的音频通过 ...