POJ 1129 平面图顶点染色
2014-08-05 09:38
375 查看
平面图顶点染色<->其对偶图(依然是个平面图)的面染色
再由四色定理,因而最多4种颜色
再由四色定理,因而最多4种颜色
//0 ms #include<cstdio> #include<algorithm> #include<cstring> using namespace std; #define N 30 char s[100],cc; bool map ; int c ,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(); } } /* 6 A:BEF B:AC C:BD D:CEF E:ADF F:ADE */
相关文章推荐
- POJ 1129 Channel Allocation 平面图染色问题
- POJ 1129-Channel Allocation(顶点着色)
- poj 1129 Channel Allocation (DFS 图的染色问题)
- POJ1129 Channel Allocation——染色问题 暴搜
- POJ 1129 Channel Allocation(染色)
- poj1129-Channel Allocation(搜索练习6-染色)
- POJ 1129 Channel Allocation 图的染色 最大团
- (一般)POJ-1129 染色,DFS技巧
- POJ 1129 图的染色 暴力
- poj1129 平面图点着色
- POJ1129 Channel Allocation [图染色 暴搜]
- 相邻区域染色最小染色数问题 POJ 1129
- POJ 1129 Channel Allocation (暴力搜索)
- POJ 1129 Channel Allocation(DFS)
- poj 1129 Channel Allocation(四色定理)
- POJ 1129
- POJ 2528【线段树染色+离散化】
- POJ 1436 Horizontally VisibleSegments(线段树:区间覆盖染色)
- poj 3041-Asteroids-最小顶点覆盖
- hdu 3360 National Treasures(最小顶点覆盖,黑白染色)