#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. 2018.08.21 NOIP模拟 xorand(01trie)

    xorand 描述 有q次操作,每次操作是以下两种: 1. 加入一个数到集合中 2. 查询,查询当前数字与集合中的数字的最大异或值,最大and值,最大or值 输入 第一行1个正整数Q表示操作次数 接下 ...

  2. 《C++ Primer (V4)》读书笔记

    第2章 变量和基本类型 1.(P56)如果使用class关键字来定义类,那么定义在第一个访问标号前的任何成员都隐式指定为private:如果使用struct关键字,那么这些成员都是public. 第7 ...

  3. SQL之mysql常用操作语句(入门级)

    1.进入数据库: mysql -u root -p mysql -h localhost -u root -p database_name 2.列出数据库 show databases; 3.选择数据 ...

  4. UVa 11346 Probability (转化+积分+概率)

    题意:给定a,b,s,在[-a, a]*[-b, b]区域内任取一点p,求以原点(0,0)和p为对角线的长方形面积大于s的概率. 析:应该明白,这个和高中数学的东西差不多,基本就是一个求概率的题,只不 ...

  5. Proxy Hosted Virtual

    http://books.sonatype.com/nexus-book/reference/confignx-sect-manage-repo.html Public Repositories 对外 ...

  6. HDU1175 连连看(bfs) 2016-07-24 13:27 115人阅读 评论(0) 收藏

    连连看 Problem Description "连连看"相信很多人都玩过.没玩过也没关系,下面我给大家介绍一下游戏规则:在一个棋盘中,放了很多的棋子.如果某两个相同的棋子,可以通 ...

  7. hdu4417(Super Mario)—— 二分+划分树

    Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  8. Linq的基本用用法

    Linq 的基本用法: Sort , OrderBy, Skip,Take,Where,Compare,Join,Distinct ,InsertRange 等关键词 Select用法 var sel ...

  9. SSH登录警告(WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!)

    在配置本机与docker容器实现ssh无密码访问时出现以下报错 # federico @ linux in ~ [18:35:52] C:127$ sudo ssh-copy-id -i .ssh/i ...

  10. asp.net Mvc 模型绑定项目过多会导致页面运行时间卡

    asp.net Mvc 模型绑定项目过多会导致页面运行时间卡的问题. 解决方式就是采用ModelView方式进行精简,已减少模型绑定及验证的时间.