m图着色问题
2009-03-08 18:14
176 查看
#include <iostream> using namespace std; class Color { friend int mColoring(int,int,int**); private: bool OK(int); void Trace(int); int n; int m; int** a; int* x; long sum; }; bool Color::OK(int k) { for(int j = 1; j <= n; j++) if( (a[k][j] == 1) && (x[j] == x[k]) ) return false; return true; } void Color::Trace(int t) { if( t > n ) { sum ++; } else{ for(int i = 1; i<= m; i++) { x[t] = i; if( OK(t)) Trace(t+1); x[t] = 0; } } } int mColoring(int n,int m,int** a) { Color z; z.n = n; z.m = m; z.a = a; z.sum = 0; int* p = new int[n+1]; for(int i = 0; i <= n; i++) p[i] = 0; z.x = p; z.Trace(1); delete []p; return z.sum; } int main() { int nodeNum,colorNum; cin>>nodeNum>>colorNum; int** mm = new int*[nodeNum+1]; for(int i = 1; i <= nodeNum; i++) { mm[i] = new int[nodeNum+1]; for(int j = 1; j <= nodeNum; j++) cin>>mm[i][j]; } cout<<mColoring(nodeNum,colorNum,mm); for(int i = 1; i <= nodeNum; i++) delete []mm[i]; delete []mm; return 0; }
相关文章推荐
- poj 1129Channel Allocation(图着色问题)
- POJ 2528 Mayor's posters 线段树 着色问题
- 图的m着色问题
- 图的m着色问题pascal程序
- 教室课程调度问题的两种解法(区间着色问题)
- PTA 图着色问题
- 图的m着色问题
- 采用C++实现区间图着色问题(贪心算法)实例详解
- vi编辑代码无法语法着色的问题
- POJ 1129 Channel Allocation DFS搜索 着色问题
- POJ 1419 Graph Coloring 图的着色 最大团问题
- 个人总结-----非贪心算法的图的m着色判断及优化问题
- P2819 图的m着色问题 洛谷
- 图的着色问题 (也就是最少着色问题,时间复杂度为N^2)
- 算法java实现--回溯法--图的m着色问题
- Eclipse 文件太长,导致着色异常问题
- 数据结构实验--地图着色问题
- qscoj53(图的m着色问题)
- C语言使用回溯法解旅行售货员问题与图的m着色问题
- 解决代码着色组件SyntaxHighlighter行号显示问题