POJ 1129
- #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的更多相关文章
- 迭代加深搜索 POJ 1129 Channel Allocation
POJ 1129 Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14191 Acc ...
- poj 1129 Channel Allocation ( dfs )
题目:http://poj.org/problem?id=1129 题意:求最小m,使平面图能染成m色,相邻两块不同色由四色定理可知顶点最多需要4种颜色即可.我们于是从1开始试到3即可. #inclu ...
- POJ 1129 Channel Allocation 四色定理dfs
题目: http://poj.org/problem?id=1129 开始没读懂题,看discuss的做法,都是循环枚举的,很麻烦.然后我就决定dfs,调试了半天终于0ms A了. #include ...
- poj 1129 Channel Allocation
http://poj.org/problem?id=1129 import java.util.*; import java.math.*; public class Main { public st ...
- poj 1129(dfs+图的四色定理)
题目链接:http://poj.org/problem?id=1129 思路:根据图的四色定理,最多四种颜色就能满足题意,使得相邻的两部分颜色不同.而最多又只有26个点,因此直接dfs即可. #inc ...
- 四色定理+dfs(poj 1129)
题目:Channel Allocation 题意:要求A:BCD,A与B,C,D都不相同,求不同的值,典型的四色定理: #include <iostream> #include <a ...
- Channel Allocation (poj 1129 dfs)
Language: Default Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12 ...
- poj 1129 搜索
Channel Allocation Time Limit: 1000 MS Memory Limit: 10000 KB 64-bit integer IO format: %I64d , %I64 ...
- POJ 1129 Channel Allocation(DFS)
Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13173 Accepted: 67 ...
随机推荐
- 2018.08.28 洛谷P3345 [ZJOI2015]幻想乡战略游戏(点分树)
传送门 题目就是要求维护带权重心. 因此破题的关键点自然就是带权重心的性质. 这时发现直接找带权重心是O(n)的,考虑优化方案. 发现点分树的树高是logn级别的,并且对于以u为根的树,带权重心要么就 ...
- python将字典中的数据保存到文件中
d = {'a':'aaa','b':'bbb'}s = str(d)f = open('dict.txt','w')f.writelines(s)f.close()
- (连通图 模板题 无向图求割点)Network --UVA--315(POJ--1144)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- 机器学习---K最近邻(k-Nearest Neighbour,KNN)分类算法
K最近邻(k-Nearest Neighbour,KNN)分类算法 1.K最近邻(k-Nearest Neighbour,KNN) K最近邻(k-Nearest Neighbour,KNN)分类算法, ...
- what is HTTP OPTIONS verb
The options verb is sent by browser to see if server accept cross origin request or not, this proces ...
- Node.js-Usage & Example
Usage# node [options] [v8 options] [script.js | -e "script"] [arguments] Please see the Co ...
- JPA注解指南
PA注解持久化类很方便,需要jar包:ejb3-persistence.jar.我用以下三个类来说明用法. @SuppressWarnings("serial") @Entity ...
- Angular6 学习笔记——组件详解之模板语法
angular6.x系列的学习笔记记录,仍在不断完善中,学习地址: https://www.angular.cn/guide/template-syntax http://www.ngfans.net ...
- .Net Core + NGINX跳转登录时端口丢失
使用.Net Core + NGINX部署到服务器的时候,如果端口不是使用默认的80端口,在跳转到登录页面时,URL中的端口丢失. NGINX的配置如下: server { listen ; loca ...
- XML文件之创建
1.创建XML文档对象XmlDocument doc=new XmlDocument() 2.创建XML根节点变量XmlElement xmlElement 3.判断XML文件是否已经存在 1)若存在 ...