代码改变世界

随笔档案-2011年9月26日

动态规划-------最大子段和

2011-09-26 10:55 by ...平..淡..., 306 阅读, 收藏,
摘要: 最大子段和 1 /* 2 b[]的递归式为 3 b[j]={ b[j-1]+a[j] , b[j-1]>=0 4 a[j] , b[j-1]<0 } 5 */ 6 #include <iostream> 7 using namespace std; 8 9 int MaxSum(int n, int *a)10 {11 int sum=0; 12 int b=0;13 for (int i=0;i<n;i++)14 {15 if (b>0) b+=a[i]; else b=a[i];16... 阅读全文

回溯法-------迷宫问题

2011-09-26 10:04 by ...平..淡..., 201 阅读, 收藏,
摘要: 迷宫问题 1 #include <iostream> 2 using namespace std; 3 4 int flag = 0; 5 const int m = 5; 6 const int n = 5; 7 int a[m][n] = { 8 {0,0,0,1,1}, 9 {1,0,0,0,0},10 {0,1,1,0,1},11 {1,0,0,0,0},12 {0,1,0,1,0}13 };14 void search(int x,int y)15 {16 if((x==m-1)&&(y... 阅读全文