题目:Channel Allocation

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

  

  1. #include <iostream>
  2. #include <algorithm>
  3. #include <stdlib.h>
  4. #include <time.h>
  5. #include <cmath>
  6. #include <cstdio>
  7. #include <string>
  8. #include <cstring>
  9. #include <vector>
  10. #include <queue>
  11. #include <stack>
  12. #include <set>
  13.  
  14. #define c_false ios_base::sync_with_stdio(false); cin.tie(0)
  15. #define INF 0x3f3f3f3f
  16. #define INFL 0x3f3f3f3f3f3f3f3f
  17. #define zero_(x,y) memset(x , y , sizeof(x))
  18. #define zero(x) memset(x , 0 , sizeof(x))
  19. #define MAX(x) memset(x , 0x3f ,sizeof(x))
  20. #define swa(x,y) {LL s;s=x;x=y;y=s;}
  21. using namespace std ;
  22. #define N 105
  23.  
  24. const double PI = acos(-1.0);
  25. typedef long long LL ;
  26.  
  27. int mapp[N][N], color[N];
  28. int col,flag;
  29. int n;
  30. string s;
  31. bool ok(int i){
  32. for(int j = ; j <= ; j++){
  33. if(!mapp[i][j]) continue;
  34. if(color[i] == color[j]) return false;
  35. }
  36. return true;
  37. }
  38.  
  39. void dfs(int num){
  40. if(num > n) {flag = ; return ;}
  41. for(int i = ; i <= col; i ++){
  42. color[num] = i;
  43. if(ok(num))
  44. dfs(num+);
  45. color[num]= ; ///记得回溯时要清零啊!!!
  46. }
  47. }
  48.  
  49. int main(){
  50. //freopen("in.txt","r",stdin);
  51. //freopen("out.txt","w",stdout);
  52. while(cin>>n && n){
  53. flag = ;
  54. zero(mapp);
  55. for(int i = ; i< n;i++){
  56. cin>>s;
  57. int k = s.size();
  58. int x,y;
  59. for(int j = ;j< k;j++){
  60. x = s[] - 'A' +;
  61. y = s[j] - 'A' +;
  62. mapp[x][y] = mapp[y][x] = ;
  63. }
  64. }
  65. for(col = ; col <= ; col++){
  66. dfs();
  67. if(flag) break;
  68. }
  69. if(col == )
  70. printf("%d channel needed.\n", col);
  71. else
  72. printf("%d channels needed.\n", col);
  73. }
  74. return ;
  75. }

四色定理+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. 16. Copy List with Random Pointer

    类同:剑指 Offer 题目汇总索引第26题 Copy List with Random Pointer A linked list is given such that each node cont ...

  2. Windows 2008等操作系统升级时出现800F0818错误代码的解决方法

    今天我在网络中的一台Windows Server 2008 R2升级时,出现“代码800F0818”的错误提示,如图1-1所示.

  3. js实现右侧的分享效果

    就是当鼠标移到上面的时候,他会出现,鼠标移出就消失. nmouseover和nmouseout就能实现 <style> *{padding:0;margin:0;} #s1{width:2 ...

  4. DataSet读取XML

    string file = File.ReadAllText("c://123.xml", Encoding.Default); using (DataSet ds = new D ...

  5. python笔记一

    好奇,想一探究竟.安装就出点小问题,win7,64位,一直卡在这里不动了? 只好取消.第二天安装仍是如此. 于是下载Windows6.1-KB2999226-x64.msu,安装,仍卡顿不动: 于是找 ...

  6. python迭代器与生成器

    1.迭代器 iterator 迭代器是一种对象类型!可以由生成器生成! 迭代器对象从集合的第一个元素开始访问,直到所有的元素被访问完结束.迭代器的一大优点是不要求事先准备好整个迭代过程中所有的元素.迭 ...

  7. PHPDocument 代码注释规范总结

    PHPDocument 代码注释规范 1. 安装phpDocumentor(不推荐命令行安装)在http://manual.phpdoc.org/下载最新版本的PhpDoc放在web服务器目录下使得通 ...

  8. APP测试工具之TraceView卡顿检测

    Traceview卡顿检测 Traceview是Android平台特有的数据采集和分析工具,集成在DDMS工具中,可以采集程序中的方法执行耗时.调用关系.调用次数以及资源占用等情况. 一.使用方法 1 ...

  9. 【转载】OpenGL超级宝典笔记——GLSL语言基础

    变量 GLSL的变量命名方式与C语言类似.变量的名称可以使用字母,数字以及下划线,但变量名不能以数字开头,还有变量名不能以gl_作为前缀,这个是GLSL保留的前缀,用于GLSL的内部变量.当然还有一些 ...

  10. socket编程相关的结构体和字节序转换、IP、PORT转换函数

    注意:结构体之间不能直接进行强制转换, 必须先转换成指针类型才可以进行结构体间的类型转换, 这里需要明确的定义就是什么才叫强制转换. 强制转换是将内存中一段代码以另一种不同类型的方式进行解读, 因此转 ...