
算法设计与分析
一只会旅行的猫
这个作者很懒,什么都没留下…
展开
-
第五章 回溯法
5.2 装载问题 #include #include #include using namespace std; const int NM=100; int wi[NM],path[NM],x[NM],n,bestmax,Wleft,c; void Backtrack(int cw,int i) { if(i>n){ bestmax=cw; for(int j=1;j<=n;原创 2014-03-13 13:02:55 · 585 阅读 · 0 评论 -
第五章 习题(二)
5-9 拉丁矩阵问题 #include #include #include using namespace std; const int NM=25; int x[NM][NM],n,m,num,sum; bool check(int line,int row,int k) { int i,j; for(i=0;i<line;i++){ if(x[i][row]==k) ret原创 2014-03-22 13:56:57 · 684 阅读 · 0 评论 -
第三章 习题(三)
5-12 罗密欧与朱丽叶的迷宫问题 注意:还可加入无解时的剪枝判断 [cpp] view plaincopyprint? #include #include #include using namespace std; const int NM=25; int d[8][2]={-1,0,-1,1,原创 2014-03-23 23:33:46 · 1146 阅读 · 0 评论 -
第五章 习题(一)
5-1 子集和问题 #include #include #include using namespace std; const int NM=25; int set[NM],x[NM],path[NM],n,Wleft,c; bool Backtrack(int cw,int t) { if(t>n){ for(int j=1;j<=n;j++) path[j]=x[j];原创 2014-03-18 14:50:37 · 746 阅读 · 0 评论 -
第四章 贪心算法
4.1 活动安排问题 分析:按照结束时间非递减排序,再贪心。 #include #include #include #include using namespace std; const int NM=105; bool x[NM]; struct Node{ int s,f; }q[NM]; bool comp(struct Node A,struct Node B){ re原创 2014-04-03 11:48:07 · 531 阅读 · 0 评论 -
第二章 递归与分治策略
2-5 整数划分问题原创 2014-04-08 14:55:02 · 466 阅读 · 0 评论