1. #include<iostream>
  2. #include<stdio.h>
  3. #include<string>
  4. #define MAXN 60
  5. using namespace std;
  6. int max_clique(int n, int * * mat, int *ret) ;
  7. int main()
  8. {
  9. //freopen("acm.acm","r",stdin);
  10. int i;
  11. int ans;
  12. int j;
  13. string s;
  14. int num;
  15. int * * _m;
  16. int * ret;
  17. while(cin>>num)
  18. {
  19. if(num == )
  20. break;
  21. _m = new int * [num];
  22. ret = new int[num];
  23. for(i = ; i < num; ++ i)
  24. {
  25. _m[i] = new int[num];
  26. memset(_m[i],,sizeof(int)*num);
  27. }
  28. //for(i = 0; i < num; ++ i)
  29. // for(j = 0; j < num; ++ j)
  30. // cout<<_m[i][j]<<" ";
  31. for(i = ; i < num; ++ i)
  32. {
  33. cin>>s;
  34. if(s.length() == )
  35. continue;
  36. else
  37. {
  38. for(j = ; j < s.length(); ++ j)
  39. {
  40. _m[s[] - 'A'][s[j] - 'A'] = ;
  41. }
  42. }
  43. }
  44. ans = max_clique(num,_m,ret);
  45. cout<<ans;
  46. if(ans == )
  47. cout<<" channel needed."<<endl;
  48. else
  49. cout<<" channels needed."<<endl;
  50. delete [] _m;
  51. delete ret;
  52. }
  53. }
  54.  
  55. void clique(int n, int* u, int * * mat, int size, int& max, int& bb, int * res, int* rr, int* c) {
  56. int i, j, vn, v[MAXN];
  57. if (n) {
  58. if (size + c[u[]] <= max) return;
  59. for (i = ; i < n + size - max && i < n; ++ i) {
  60. for (j = i + , vn = ; j < n; ++ j)
  61. if (mat[u[i]][u[j]])
  62. v[vn ++] = u[j];
  63. rr[size] = u[i];
  64. clique(vn, v, mat, size + , max, bb, res, rr, c);
  65. if (bb) return;
  66. }
  67. } else if (size > max) {
  68. max = size;
  69. for (i = ; i < size; ++ i)
  70. res[i] = rr[i];
  71. bb = ;
  72. }
  73. }
  74.  
  75. int max_clique(int n, int * *mat, int * ret) {
  76. int max = , bb, c[MAXN], i, j;
  77. int vn, v[MAXN], rr[MAXN];
  78. for (c[i = n - ] = ; i >= ; -- i) {
  79. for (vn = , j = i + ; j < n; ++ j)
  80. if (mat[i][j])
  81. v[vn ++] = j;
  82. bb = ;
  83. rr[] = i;
  84. clique(vn, v, mat, , max, bb, ret, rr, c);
  85. c[i] = max;
  86. }
  87. return max;
  88. }

关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。

技术网站地址: vmfor.com

POJ 1129的更多相关文章

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

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

  2. poj 1129 Channel Allocation ( dfs )

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

  3. POJ 1129 Channel Allocation 四色定理dfs

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

  4. poj 1129 Channel Allocation

    http://poj.org/problem?id=1129 import java.util.*; import java.math.*; public class Main { public st ...

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

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

  6. 四色定理+dfs(poj 1129)

    题目:Channel Allocation 题意:要求A:BCD,A与B,C,D都不相同,求不同的值,典型的四色定理: #include <iostream> #include <a ...

  7. Channel Allocation (poj 1129 dfs)

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

  8. poj 1129 搜索

    Channel Allocation Time Limit: 1000 MS Memory Limit: 10000 KB 64-bit integer IO format: %I64d , %I64 ...

  9. POJ 1129 Channel Allocation(DFS)

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

随机推荐

  1. 2018.08.28 洛谷P3345 [ZJOI2015]幻想乡战略游戏(点分树)

    传送门 题目就是要求维护带权重心. 因此破题的关键点自然就是带权重心的性质. 这时发现直接找带权重心是O(n)的,考虑优化方案. 发现点分树的树高是logn级别的,并且对于以u为根的树,带权重心要么就 ...

  2. python将字典中的数据保存到文件中

    d = {'a':'aaa','b':'bbb'}s = str(d)f = open('dict.txt','w')f.writelines(s)f.close()

  3. (连通图 模板题 无向图求割点)Network --UVA--315(POJ--1144)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  4. 机器学习---K最近邻(k-Nearest Neighbour,KNN)分类算法

    K最近邻(k-Nearest Neighbour,KNN)分类算法 1.K最近邻(k-Nearest Neighbour,KNN) K最近邻(k-Nearest Neighbour,KNN)分类算法, ...

  5. what is HTTP OPTIONS verb

    The options verb is sent by browser to see if server accept cross origin request or not, this proces ...

  6. Node.js-Usage & Example

    Usage# node [options] [v8 options] [script.js | -e "script"] [arguments] Please see the Co ...

  7. JPA注解指南

    PA注解持久化类很方便,需要jar包:ejb3-persistence.jar.我用以下三个类来说明用法. @SuppressWarnings("serial") @Entity ...

  8. Angular6 学习笔记——组件详解之模板语法

    angular6.x系列的学习笔记记录,仍在不断完善中,学习地址: https://www.angular.cn/guide/template-syntax http://www.ngfans.net ...

  9. .Net Core + NGINX跳转登录时端口丢失

    使用.Net Core + NGINX部署到服务器的时候,如果端口不是使用默认的80端口,在跳转到登录页面时,URL中的端口丢失. NGINX的配置如下: server { listen ; loca ...

  10. XML文件之创建

    1.创建XML文档对象XmlDocument doc=new XmlDocument() 2.创建XML根节点变量XmlElement xmlElement 3.判断XML文件是否已经存在 1)若存在 ...