POJ 1129 平面图顶点染色
来源:互联网 发布:淘宝扫码怎么扫 编辑:程序博客网 时间:2024/05/01 13:37
平面图顶点染色<->其对偶图(依然是个平面图)的面染色
再由四色定理,因而最多4种颜色
//0 ms#include<cstdio>#include<algorithm>#include<cstring>using namespace std;#define N 30char s[100],cc;bool map[N][N];int c[N],vis[1000000][5];int n,num,o;bool DFS(int step){ if (step > n)return true; o++;int tmp=o; memset(vis+tmp,0,sizeof(int)*5); for (int j=1; j <=n;++j) if (map[step][j]==1&&c[j]) vis[tmp][c[j]]=1; for (int i=1; i<=num;++i) if (!vis[tmp][i]) { c[step] = i; if (DFS (step + 1)) return true; } c[step]=0; return false;}void doit(){ memset(map,0,sizeof(map)); int len; for (int i=1;i<=n;i++) { scanf("%c:",&cc); gets(s); len=strlen(s); for (int j=0;j<len;j++) map[cc-'A'+1][s[j]-'A'+1]=1; } int ans; for (ans=1;;ans++)//由四色问题ans应不超过4 { memset(c,0,sizeof(c)); o=0; num=ans; if (DFS(1)) break; } if (ans==1)printf("1 channel needed.\n"); else printf("%d channels needed.\n",ans);}int main(){ while (scanf("%d",&n),n) {gets(s); doit(); }}/*6A:BEFB:ACC:BDD:CEFE:ADFF:ADE*/
0 0
- POJ 1129 平面图顶点染色
- POJ 1129 Channel Allocation 平面图染色问题
- POJ 1129 Channel Allocation(染色)
- 相邻区域染色最小染色数问题 POJ 1129
- (一般)POJ-1129 染色,DFS技巧
- POJ 1129 图的染色 暴力
- 趣题:平面图三染色的零知识证明
- 读取点云 .OBJ 文件,画出顶点平面图
- POJ 1129-Channel Allocation(顶点着色)
- 平面图
- poj 1112 染色+DP
- poj 1129Channel Allocation(染色问题, DFS)
- poj 1129 Channel Allocation (DFS 图的染色问题)
- POJ 1129 Channel Allocation 图的染色 最大团
- hdu 3360 National Treasures(最小顶点覆盖,黑白染色)
- 二分图+染色 poj 2492
- 【最小顶点覆盖】POJ 3041
- 【最小顶点覆盖】POJ 2226
- 超时原因
- HDU 4902 Nice boat(线段树 区间更新)
- HDU 4786 Fibonacci Tree 生成树
- POJ 2503 Babelfish
- mysql的数据类型
- POJ 1129 平面图顶点染色
- GetCurrentTime(),GetLocalTime(),GetSystemTime()之间的区别
- Webview 自适应屏幕
- 访问被封锁的网站在中国的最佳的VPN用于Mac OS X
- 制作系统光盘Server 2003 总结
- #pragma warning(disable : 4786) 的用处
- Android学习——CursorAdapter
- 关于presentation 中连接词的 使用
- 计划迁移然后武装自己的VPN