#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. IntelliJ IDEA 2017版 编译器使用学习笔记(三) (图文详尽版);IDE快捷键使用

    一.列操作 功能:操作多行列执行相同的功能,达到一次修改多行同类型数据的情况,如图:                 Json字符串,转为枚举类的字段: 首先进行,快捷键一行快速操作 1.选中命令,s ...

  2. 继承方法-->原型的相互引用

    function Father(){} Father.prototype.name = 'zhang'; function Son(){} function inherit(Target,Orgin) ...

  3. 记一次项目使用webuploader爬坑之旅

       因前端页面开发使用的为VUE开发,又要支持IE9,遂只有基于webuploader封装一个上传组件.地址:https://github.com/z719725611/vue-upload-web ...

  4. Git 同步远程仓库

    在你经常使用的命令当中有一个git branch –a 用来查看所有的分支,包括本地和远程的.但是时间长了你会发现有些分支在远程其实早就被删除了,但是在你本地依然可以看见这些被删除的分支. 同步远程分 ...

  5. NSData与UIImage之间的转换

    1 //NSData转换为UIImage 2 NSData *imageData = [NSData dataWithContentsOfFile: imagePath]; 3 UIImage *im ...

  6. Mac突然没有声音但是重启后可以恢复

    命令行操作方式   今天又发现了Mac上的一个BUG,有时候在工作之余我们去吃饭的时候Mac经常会进入睡眠状态,但是有的时候从睡眠状态激活后,本来想听个音乐,但是突然发现音乐不可以用了,以前每次都是重 ...

  7. JAX_WS 2.2 规范的webservices客户端实现(Axis2,Cxf)

    为了对接之前老版本的接口,折腾了好几个小时. 主要是目前我的程序采用的是axis2的jax_rpc方式发布webservices服务,用这种服务的客户端,去调用老版本的jax_ws 2.2的接口,会报 ...

  8. SQL 取两日期的记录

    SELECT TOP 1000 [ID]      ,[SourcePageID]      ,[PlatformType]      ,[CreateTime]  FROM [home_sendor ...

  9. [ASP.NET]Net Framework环境问题的一种修复方案

    一.情况介绍 造价软件基于.net framework 4.0开发,要成功运行需要在目标电脑上安装4.0版本以上的framework.一般情况下xp是没有的,win7系列自带3.5,都需要手动安装4. ...

  10. leetcode 最后一个单词的长度

    给定一个仅包含大小写字母和空格 ' ' 的字符串,返回其最后一个单词的长度. 如果不存在最后一个单词,请返回 0 . 说明:一个单词是指由字母组成,但不包含任何空格的字符串. 示例: 输入: &quo ...