#include<iostream>
#include<stdio.h>
#include<string>
#define MAXN 60
using namespace std;
int max_clique(int n, int * * mat, int *ret) ;
int main()
{
//freopen("acm.acm","r",stdin);
int i;
int ans;
int j;
string s;
int num;
int * * _m;
int * ret;
while(cin>>num)
{
if(num == )
break;
_m = new int * [num];
ret = new int[num];
for(i = ; i < num; ++ i)
{
_m[i] = new int[num];
memset(_m[i],,sizeof(int)*num);
}
//for(i = 0; i < num; ++ i)
// for(j = 0; j < num; ++ j)
// cout<<_m[i][j]<<" ";
for(i = ; i < num; ++ i)
{
cin>>s;
if(s.length() == )
continue;
else
{
for(j = ; j < s.length(); ++ j)
{
_m[s[] - 'A'][s[j] - 'A'] = ;
}
}
}
ans = max_clique(num,_m,ret);
cout<<ans;
if(ans == )
cout<<" channel needed."<<endl;
else
cout<<" channels needed."<<endl;
delete [] _m;
delete ret;
}
} void clique(int n, int* u, int * * mat, int size, int& max, int& bb, int * res, int* rr, int* c) {
int i, j, vn, v[MAXN];
if (n) {
if (size + c[u[]] <= max) return;
for (i = ; i < n + size - max && i < n; ++ i) {
for (j = i + , vn = ; j < n; ++ j)
if (mat[u[i]][u[j]])
v[vn ++] = u[j];
rr[size] = u[i];
clique(vn, v, mat, size + , max, bb, res, rr, c);
if (bb) return;
}
} else if (size > max) {
max = size;
for (i = ; i < size; ++ i)
res[i] = rr[i];
bb = ;
}
} int max_clique(int n, int * *mat, int * ret) {
int max = , bb, c[MAXN], i, j;
int vn, v[MAXN], rr[MAXN];
for (c[i = n - ] = ; i >= ; -- i) {
for (vn = , j = i + ; j < n; ++ j)
if (mat[i][j])
v[vn ++] = j;
bb = ;
rr[] = i;
clique(vn, v, mat, , max, bb, ret, rr, c);
c[i] = max;
}
return max;
}

关注我的公众号,当然,如果你对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. Fibonacci number

    https://github.com/Premiumlab/Python-for-Algorithms--Data-Structures--and-Interviews/blob/master/Moc ...

  2. KBMMW 4.81.00 发布

    这次更新的速度非常快. 4.81.00 May 9 2015 Important notes (changes that may break existing code) ============== ...

  3. window server2012服务器上如何安装nginx并启动

    window环境下,Nginx安装启动的步骤如下: 把下载的window下的安装包,解压到一个不包含空格的路径下,比如:d:/Nginx 打开命令行窗口[win+R 输入cmd,然后确定]. 进入解压 ...

  4. 2018.09.23 codeforces 1053B. Vasya and Good Sequences(前缀和)

    传送门 考试的时候卡了一会儿. 显然这个答案只跟二进制位为1的数量有关. 还有一个显然的结论. 对于一个区间[l,r][l,r][l,r],如果其中单个数二进制位为1的数量最大值不到区间所有数二进制位 ...

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

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

  6. 如何开发一个产品级的Node.js 应用

    介绍 Node.js是一个开源的javascript运行时环境.非常简单可以快速开发一个网络应用.这个平台运行在Linux.OSX和Windows,而且运行在这个平台上的应用都是用javascript ...

  7. Netty Nio启动全流程

    Netty Nio启动全流程 1. 各组件之间的关系 说明:EventLoopGroup类似线程池,EventLoop为单线程,每个EventLoop关联一个Nio Selector,用于注册Chan ...

  8. laravel命令

    新建控制器 php artisan make:controller IssuesController 新建控制器并自动生成对应RESTful风格路由相关CURD方法 php artisan make: ...

  9. 【TFS 2017】使用浏览器上传文件(TFVC)或者编辑代码,错误提示TF14098,需要对文件有PendChange 权限

    从TFS 2015开始,微软在TFS系统中增加了一个非常吸引开发人员的功能,"快速代码编辑器" (Quick Code Editor).使用这个功能,你可以在任何安装了浏览器的设备 ...

  10. NavigationViewController页面间通信及传值

    使用进行页面跳转时,应该使用方法来跳转至下一页面,这样的话,下一页面同样在容器中. 1AloneSetPrizeViewController *setPrize = [[AloneSetPrizeVi ...