hdu1087
2016-01-15 00:00
183 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1087
View Code
dfs(tle)
View Code
// dp问题: // 状态转移方程 b[i]=max(b[i], b[j]+a[i]); #include " iostream " using namespace std; #define M 1010 int n; int a[M],b[M]; int i,j; int main() { while (cin >> n,n) { int Max =- 0xffff ; memset(b, 0 , sizeof ( 0 )); for (i = 0 ;i < n;i ++ ) cin >> a[i]; b[ 0 ] = a[ 0 ]; for (i = 1 ;i < n;i ++ ) { b[i] = a[i]; for (j = 0 ;j < i;j ++ ) if (a[j] < a[i] && b[i] < b[j] + a[i]) b[i] = b[j] + a[i]; if (b[i] > Max) Max = b[i]; } cout << Max << endl; } return 0 ; }
dfs(tle)
#include " iostream " using namespace std; int a[ 1010 ]; int n,sum; int p = 0 ; void dfs( int x, int y) { while (y <= x && x < n) y ++ ; if (a[x] < a[y] && y < n && x < n) { sum += a[y]; x = y; if (x < n - 1 && y < n - 1 ) dfs(x,y); } else if (y < n - 1 ){ y ++ ; if (y < n - 1 ) dfs(x,y);} } int main() { int i,j; while (cin >> n,n) { for (i = 0 ;i < n;i ++ ) cin >> a[i]; int Max =- 1 ; sum = 0 ; for (i = 0 ;i < n;i ++ ) { sum = a[i]; if (Max < sum) Max = sum; for (j = i + 1 ; j < n; j ++ ) { p = 0 ; if (a[i] < a[j]) { sum += a[j]; dfs(j,p); } if (sum > Max) Max = sum; sum = a[i]; } } cout << Max << endl; } return 0 ; }
相关文章推荐
- 最优子序列求和DP算法(效率较高)
- (六)hadoop系列之__hadoop分布式集群环境搭建
- poj1423
- PS制作圆角透明图片
- poj1316(非打表)
- 百度地图生产工具
- hdu2707
- poj1458(LCS)
- structure
- C#基础知识(以宝马,车,车轮为例)
- 前n项和!
- 拓扑排序(1)
- 《麦肯锡入职培训第一课》读书感悟
- Residual Networks <2015 ICCV, ImageNet 图像分类Top1>
- 启动图&图标
- dp(题型小结)
- linux之shell脚本学习篇一
- 社会要反思:高三学生学校坠亡 当天曾致电父亲称压力大
- 【转】别人整理的DP大全
- 链表的删除(3)