最小哈密顿回路
来源:互联网 发布:播放器软件下载 编辑:程序博客网 时间:2024/06/09 21:07
老杨留的作业,折腾几个小时加上参考别人的终于写出来了,还是很弱啊。效率貌似还可以,强化了分支定界的条件之后计算N=20的情况只需要十几秒。好好体会一下~
#include #include #include #include using namespace std;#define N 15int curLightestWeight = 1000000;int curDepth = 0;int curWeight = 0;int depth;int curCircle[N],bestCircle[N];bool used[N];int p[N][N];void update();void show();void genGraphic(int maxWeight){for(int i = 0;i < N;i++){for(int j = 0;j < N;j++){if(i == j)p[i][j] = 0;elsep[i][j] = rand()%maxWeight + 1;}}for(int i = 0;i < N;i++){for(int j = 0;j < N;j++){cout<<<" "; } cout<= curLightestWeight){curDepth--;used[curVertex] = false;return;}else if(curDepth == depth){int thisWeight = p[curVertex][0];curWeight += thisWeight;if(curWeight < curLightestWeight){curLightestWeight = curWeight;update();}curDepth--;used[curVertex] = false;curWeight -= thisWeight;return;} else{for(int i = 0;i < N;i++){if(i == curVertex || used[i] == true)continue;int thisWeight = p[curVertex][i];curWeight += thisWeight;MHC_recursion(i);curWeight -= thisWeight; } }used[curVertex] = false;curDepth--;return;}void update(){for(int i = 0;i < N;i++)bestCircle[i] = curCircle[i];}void show(){for(int i = 0;i < N;i++)cout<<<"-->";cout<<<<"The weight of the circle is "<<<"."<
- 最小哈密顿回路
- 哈密顿回路
- poj3229 哈密顿回路
- poj3311 哈密顿回路
- 哈密顿回路模版
- Hamilton-哈密顿回路
- 哈密顿回路
- 哈密顿回路
- POJ2438-求解哈密顿回路
- poj 2438哈密顿回路
- HDU4337(哈密顿回路)
- 哈密顿回路及解法
- 欧拉回路及哈密顿回路
- 哈密顿回路,状态dp poj2288
- 哈密顿回路-相异数字序列问题
- hdu3001(集合dp求哈密顿回路)
- hdu 4337 (哈密顿回路模板)
- hdu5418 最短哈密顿回路
- 分治与递归、动态规划、贪心
- protocolbuf的优势
- 一张表内自己更新自己的列值
- Kruskal Prim Dijkstra
- delphi中double或float转Integer实践
- 最小哈密顿回路
- 超级函数指针
- 那些排序算法
- [飞鸽传书]珍藏:OO五大原则
- 给激活了WS_HSCROLL,WS_VSCROLL的RichEdit增加自动换行的控制
- 常用的一些javascript小技巧
- insert语句优化
- 从程序员到asp.net架构师转变
- 测试用例基本格式