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

题意:求最小m,使平面图能染成m色,相邻两块不同色
由四色定理可知顶点最多需要4种颜色即可。我们于是从1开始试到3即可。

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<stack>
#include<queue>
#include<iomanip>
#include<cmath>
#include<map>
#include<vector>
#include<algorithm>
using namespace std; int n,G[][],vis[][],ans;
void pri()
{
int f=-;
for(int i=; i<; i++)
{
for(int j=; j<n; j++)
if(vis[j][i]&&f<i)
f=i;
}
if(ans>f)
ans=f;
}
void dfs(int x)
{
if(x>=n)
{
pri();
return;
}
for(int i=; i<; i++)
{
int f=;
for(int j=; j<n; j++)
{
if((G[j][x]&&vis[j][i])||(G[x][j]&&vis[j][i]))
{
f=;
break;
}
}
if(f)
{
vis[x][i]=;
dfs(x+);
vis[x][i]=;
}
}
}
int main()
{
char s[];
while(cin>>n&&n)
{
memset(G,,sizeof(G));
memset(vis,,sizeof(vis));
for(int i=; i<n; i++)
{
cin>>s;
int u=s[]-;
for(int j=; s[j]; j++)
{
int v=s[j]-;
G[u][v]=;
}
}
ans=;
vis[][]=;
dfs();
ans+=;
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: 15546   Accepted: 78 ...

  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: 13173   Accepted: 67 ...

  4. POJ 1129 Channel Allocation 四色定理dfs

    题目: http://poj.org/problem?id=1129 开始没读懂题,看discuss的做法,都是循环枚举的,很麻烦.然后我就决定dfs,调试了半天终于0ms A了. #include ...

  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. PKU 1129 Channel Allocation(染色问题||搜索+剪枝)

    题目大意建模: 一个有N个节点的无向图,要求对每个节点进行染色,使得相邻两个节点颜色都不同,问最少需要多少种颜色? 那么题目就变成了一个经典的图的染色问题 例如:N=7 A:BCDEFG B:ACDE ...

  8. Channel Allocation (poj 1129 dfs)

    Language: Default Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12 ...

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

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

随机推荐

  1. 几个好用的截取字符串的php函数分享

    分享几个好用的PHP 截取字符串函数(支持gb2312和utf-8). 1.截取GB2312字符用的函数 <?php /** **截取中文字符串 * edit by www.jbxue.com ...

  2. Android:使用命令行工具adb、mksdcard等

    有一些Android的工具需要在命令行的环境中运行,只是可以选择Windows的开始->运行,键入cmd并确定,进入命令行的界面中运行.主要的命令行工具包括adb和mksdcard等.命令行的工 ...

  3. Battle Over Cities (25)(DFS、连通图)

    It is vitally important to have all the cities connected by highways in a war. If a city is occupied ...

  4. python学习笔记9(对文件的操作)

    一.文件对象 我理解的文件对象就是一个接口,通过这个接口对文件进行相关操作. 二.相关函数 [1].内建函数:open() 提供了初始化输入/输出(I/O)操作的通用接口,成功打开一个文件后会返回一个 ...

  5. WinForm 换行问题 textbox (转)

    WinForm 换行问题 textbox 今天碰到一段string在label中能正常换行,但是在textbox中却无法换行的问题. 首先考虑是换行符的问题.在网上查了些资料: 1.TextBox 中 ...

  6. 第二好用的时间日期选择插件(jscal)

    这个是第二好用的了,支持鼠标滚动选择时间.功能很强大,文档:http://www.dynarch.com/jscal/ 效果图: <!DOCTYPE html PUBLIC            ...

  7. ArcGIS Engine实现LAS数据集转RASTER

    ArcGIS 10.1版本开始提供了将LAS数据集转换为栅格的新功能,最近在做LAS数据处理时通过ArcGIS Engine10.1+C#实现了LAS数据集转RASTER,既然ArcGIS DeskT ...

  8. GodSon Easyui 结合Pluplaod插件的文件分割上传

    自己整理了一个文件分割上传的实例,提供研究学习使用. 在线查看效果       下载该资源pluplaod文件分割上传Demo.zip 简介: 首先,进入页面会看到下面的效果: 点击一个按钮,出现如图 ...

  9. eval()字符串转成对象

    var s = "{a:1,b:2}"; console.log(typeof s); s = eval("(" + s + ")"); c ...

  10. 免费素材:25套免费的 Web UI 设计的界面元素(转)

    Web 元素是任何网站相关项目都需要的,质量和良好设计的元素对于设计师来说就像宝贝一样.如果您正在为您的网站,博客,Web 应用程序或移动应用程序寻找完美设计的网页元素,那么下面这个列表会是你需要的. ...