四色定理+dfs(poj 1129)
题意:要求A:BCD,A与B,C,D都不相同,求不同的值,典型的四色定理;
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <time.h>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <set> #define c_false ios_base::sync_with_stdio(false); cin.tie(0)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define zero_(x,y) memset(x , y , sizeof(x))
#define zero(x) memset(x , 0 , sizeof(x))
#define MAX(x) memset(x , 0x3f ,sizeof(x))
#define swa(x,y) {LL s;s=x;x=y;y=s;}
using namespace std ;
#define N 105 const double PI = acos(-1.0);
typedef long long LL ; int mapp[N][N], color[N];
int col,flag;
int n;
string s;
bool ok(int i){
for(int j = ; j <= ; j++){
if(!mapp[i][j]) continue;
if(color[i] == color[j]) return false;
}
return true;
} void dfs(int num){
if(num > n) {flag = ; return ;}
for(int i = ; i <= col; i ++){
color[num] = i;
if(ok(num))
dfs(num+);
color[num]= ; ///记得回溯时要清零啊!!!
}
} int main(){
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(cin>>n && n){
flag = ;
zero(mapp);
for(int i = ; i< n;i++){
cin>>s;
int k = s.size();
int x,y;
for(int j = ;j< k;j++){
x = s[] - 'A' +;
y = s[j] - 'A' +;
mapp[x][y] = mapp[y][x] = ;
}
}
for(col = ; col <= ; col++){
dfs();
if(flag) break;
}
if(col == )
printf("%d channel needed.\n", col);
else
printf("%d channels needed.\n", col);
}
return ;
}
四色定理+dfs(poj 1129)的更多相关文章
- 迭代加深搜索 POJ 1129 Channel Allocation
POJ 1129 Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14191 Acc ...
- poj 1129(dfs+图的四色定理)
题目链接:http://poj.org/problem?id=1129 思路:根据图的四色定理,最多四种颜色就能满足题意,使得相邻的两部分颜色不同.而最多又只有26个点,因此直接dfs即可. #inc ...
- POJ 1129 Channel Allocation 四色定理dfs
题目: http://poj.org/problem?id=1129 开始没读懂题,看discuss的做法,都是循环枚举的,很麻烦.然后我就决定dfs,调试了半天终于0ms A了. #include ...
- poj 1129 Channel Allocation ( dfs )
题目:http://poj.org/problem?id=1129 题意:求最小m,使平面图能染成m色,相邻两块不同色由四色定理可知顶点最多需要4种颜色即可.我们于是从1开始试到3即可. #inclu ...
- POJ 1129:Channel Allocation 四色定理+暴力搜索
Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13357 Accepted: 68 ...
- Channel Allocation (poj 1129 dfs)
Language: Default Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12 ...
- POJ 1129 Channel Allocation(DFS)
Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13173 Accepted: 67 ...
- poj 1129 Channel Allocation(图着色,DFS)
题意: N个中继站,相邻的中继站频道不得相同,问最少需要几个频道. 输入输出: Sample Input 2 A: B: 4 A:BC B:ACD C:ABD D:BC 4 A:BCD B:ACD C ...
- POJ 1129 Channel Allocation DFS 回溯
Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 15546 Accepted: 78 ...
随机推荐
- UNIX网络编程-send、recv、sendto、recvfrom详解
send.recv和sendto.recvfrom,一般情况下,send.recv在TCP协议下使用,sendto.recvfrom在UDP协议下使用,也可以在TCP协议下使用,不过用的很少. 1.s ...
- Django model 中meta options之 abstract
当abstract=True时,这个model就变成了abstrct base class,那这个基类有什么特性呢? 当某一model中设置了abstract=True时,就会使该model中的字段都 ...
- outlook找不到文件Outlook.pst 如何启动
首先注明:这种情况在控制面板-邮件 无法打开的情况下可以使用以下命令打开设置界面 解决方法: 1. 开始 –> 运行 –> cmd 2. 在DOS下,用CD 切换到 Outlook.ex ...
- js实现缓冲运动,和匀速运动有点不相同
缓冲运动和匀速运动有点不同,看图可以知道缓冲运动速度是越来越慢的. <style> *{ padding:0; margin:10px 0; } #div1{ height:100px; ...
- ApexSql Log 2014.04.1133破解版&补丁
已上传最新的2016版本,请移步: http://www.cnblogs.com/gsyifan/p/ApexSql_Log_2016_Crack.html 状态不好,鬼使补差的跑到服务器上updat ...
- 利用 Gulp 处理前端工作流程
最近做项目,因为每次做完后都要手动压缩CSS.JS 等文件,压缩后另存为 *.min.xxx. Less 还要手动输入命令进行编译,调整页面也经常要手动刷新页面看效果,很麻烦,就尝试用 gulp 去处 ...
- 微信 网页授权获取用户基本信息(OAuth 2.0)
// 相关设置 $APPID = ""; $AppSecret = ""; $html = ""; // 拼接 URL // 跳转该连接 获 ...
- i-doit
官网:http://www.i-doit.org/,有免费版和专业版. 开源:http://sourceforge.net/projects/i-doit/ › Features CMDB I ...
- Bootstrap 更改Navbar默认样式
alt+shift+n 新建文件ctrl+shift+/ 注释ctrl+shift+f 重新排版代码ctrl+/ 注释 /* navbar */.navbar-default { background ...
- An attempt was made to load a program with an incorrect format
用.net调用一个C++ 32位的DLL, 编译的时候选择x86, 在部署到一个64位的机器上的时候报错:"An attempt was made to load a program w ...