题目:Channel Allocation

  题意:要求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 ;
}

最新文章

  1. SQL Server快捷键
  2. 【转载】Markdown使用笔记
  3. 关于获取web应用的文件路径的注意事项
  4. Cocos2d-x 3.2 学习笔记(十)Joystick 搖杆控件
  5. LeetCode : 287. Find the Duplicate Number
  6. 502 Proxy Error。The ISA Server denied the specified Uniform Resource Locator (URL).
  7. centos下配置sftp且限制用户访问目录[转]
  8. SSH反向连接及Autossh
  9. python并发(阻塞、非阻塞、epoll)
  10. go相关知识点
  11. 强化学习基础算法入门 【PPT】
  12. 8、java5线程池之动态缓存线程池newCachedThreadPool
  13. GameObject数组
  14. 02-分页器,自定义分页器,解耦函数分页器,分页器class
  15. 简单的Stack
  16. python开发_filecmp
  17. Leetcode 590. N-ary Tree Postorder Traversal
  18. 编程技巧:使用异或操作符(XOR)交换两数值
  19. 体验SpringBoot
  20. util.inherits

热门文章

  1. pl/sql和sql的区别
  2. Oracle linux6.1配置yum本地源
  3. 直接解压msi文件
  4. 设置arc/非arc
  5. Karma: 3 - 测试覆盖率
  6. Zepto源码
  7. 二模01day1解题报告
  8. ubuntu 13.04 lighttped mysql php
  9. Redis运维的一些常用的命令总结
  10. mysql 不允许连接