题目:Channel Allocation

  题意:要求A:BCD,A与B,C,D都不相同,求不同的值,典型的四色定理;

  

#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <time.h>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <set> #define c_false ios_base::sync_with_stdio(false); cin.tie(0)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define zero_(x,y) memset(x , y , sizeof(x))
#define zero(x) memset(x , 0 , sizeof(x))
#define MAX(x) memset(x , 0x3f ,sizeof(x))
#define swa(x,y) {LL s;s=x;x=y;y=s;}
using namespace std ;
#define N 105 const double PI = acos(-1.0);
typedef long long LL ; int mapp[N][N], color[N];
int col,flag;
int n;
string s;
bool ok(int i){
for(int j = ; j <= ; j++){
if(!mapp[i][j]) continue;
if(color[i] == color[j]) return false;
}
return true;
} void dfs(int num){
if(num > n) {flag = ; return ;}
for(int i = ; i <= col; i ++){
color[num] = i;
if(ok(num))
dfs(num+);
color[num]= ; ///记得回溯时要清零啊!!!
}
} int main(){
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(cin>>n && n){
flag = ;
zero(mapp);
for(int i = ; i< n;i++){
cin>>s;
int k = s.size();
int x,y;
for(int j = ;j< k;j++){
x = s[] - 'A' +;
y = s[j] - 'A' +;
mapp[x][y] = mapp[y][x] = ;
}
}
for(col = ; col <= ; col++){
dfs();
if(flag) break;
}
if(col == )
printf("%d channel needed.\n", col);
else
printf("%d channels needed.\n", col);
}
return ;
}

四色定理+dfs(poj 1129)的更多相关文章

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

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

  2. poj 1129(dfs+图的四色定理)

    题目链接:http://poj.org/problem?id=1129 思路:根据图的四色定理,最多四种颜色就能满足题意,使得相邻的两部分颜色不同.而最多又只有26个点,因此直接dfs即可. #inc ...

  3. POJ 1129 Channel Allocation 四色定理dfs

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

  4. poj 1129 Channel Allocation ( dfs )

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

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

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

  6. Channel Allocation (poj 1129 dfs)

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

  7. POJ 1129 Channel Allocation(DFS)

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

  8. 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 ...

  9. POJ 1129 Channel Allocation DFS 回溯

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

随机推荐

  1. 手机端的click

    一:click事件的封装 手机端的click事件不是太好用, 1.点击会有延迟, 2.会出现一个灰色区域 就想到了用touch事件代替. touch事件有touchstart,touchmove,to ...

  2. 山东ACM省赛历届入口

    山东省第一届ACM大学生程序设计竞赛 山东省第二届ACM大学生程序设计竞赛 山东省第三届ACM大学生程序设计竞赛 山东省第四届ACM大学生程序设计竞赛 山东省第五届ACM大学生程序设计竞赛 山东省第六 ...

  3. MySQL-(Master-Slave)配置

    1.两台机器,安装好版本一致的MySQL 192.168.29.128 (master) MySQL-5.6.21 192.168.29.129 (slave) MySQL-5.6.21 2.配置ma ...

  4. 堆block和栈block的区分

    0. 问题所在 下面给出一段代码: - (NSArray*) getBlockArray { int num = 916; return [[NSArray alloc] initWithObject ...

  5. GIS理论(墨卡托投影、地理坐标系、地面分辨率、地图比例尺、Bing Maps Tile System)

    [注]原文 http://www.cnblogs.com/beniao/archive/2010/04/18/1714544.html 墨卡托投影(Mercator Projection),又名&qu ...

  6. linux 源码安装

    下载源码安装包,一般为.tar.gz格式 解压源码至文件夹,linux终端进入该文件夹,安装只需三步,第四步为扫尾工作: ./configure --prefix=/usr/self/文件夹名称    ...

  7. python函数,lambda表达式,三目运算,列表解析,递归

    一.自定义函数 定义函数时,函数体不执行:只有在调用函数时,函数体才执行.函数的结构: 1. def 2. 函数名 3. 函数体 def func_name(): 函数体 4. 返回值 如果没有声明返 ...

  8. NHibernate系列文章十一:NHibernate并发控制

    摘要 在同一时刻数据访问量和更新次数比较大的系统中,产生了数据的并发访问问题.并发访问使得在这样的环境中,所有用户(程序.实际用户.进程.线程等)的操作不产生负面问题. 如果不使用并发,在两个用户同时 ...

  9. C#DataGridView中的常用技巧

    0(最基本的技巧). 获取某列中的某行(某单元格)中的内容  this.currentposition = this.dataGridView1.BindingContext  [this.dataG ...

  10. php函数的引用返回

    <?php function &test(){ static $b = 1; $b += 2; return $b; } $a = &test(); $a =8; $c = te ...