hdoj 1024 Max Sum Plus Plus 【动态规划】
2015-11-10 19:49
302 查看
Max Sum Plus Plus
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 21508 Accepted Submission(s): 7202
[align=left]Problem Description[/align]
Now I think you have got an AC in Ignatius.L's "Max Sum" problem. To be a brave ACMer, we always challenge ourselves to more difficult problems. Now you are faced with a more difficult problem.
Given a consecutive number sequence S1, S2, S3, S4 ... Sx, ... Sn (1 ≤ x ≤ n ≤ 1,000,000, -32768 ≤ Sx ≤ 32767). We define
a function sum(i, j) = Si + ... + Sj (1 ≤ i ≤ j ≤ n).
Now given an integer m (m > 0), your task is to find m pairs of i and j which make sum(i1, j1) + sum(i2, j2) + sum(i3, j3) + ... + sum(im,
jm) maximal (ix ≤ iy ≤ jx or ix ≤ jy ≤ jx is not allowed).
But I`m lazy, I don't want to write a special-judge module, so you don't have to output m pairs of i and j, just output the maximal summation of sum(ix, jx)(1 ≤ x ≤ m) instead. ^_^
[align=left]Input[/align]
Each test case will begin with two integers m and n, followed by n integers S1, S2, S3 ... Sn.
Process to the end of file.
[align=left]Output[/align]
Output the maximal summation described above in one line.
[align=left]Sample Input[/align]
1 3 1 2 3 2 6 -1 4 -2 3 -2 3分析:求子段最大和。代码:[code]#include<stdio.h> #include<string.h> #include<algorithm> #define Min 0x80000000 using namespace std; const int N= 1e6+10; int pp ,bb ,dp ; int main() { int n,m,i,j,k,max; while(scanf("%d%d",&n,&m)!=EOF) { for(i=1;i<=m;i++) scanf("%d",&pp[i]); for(i=0;i<=m;i++) dp[i]=0,bb[i]=0; for(i=1;i<=n;i++) { max=Min; for(j=i;j<=m;j++) { if(dp[j-1]>bb[j-1]) dp[j]=dp[j-1]+pp[j]; else dp[j]=bb[j-1]+pp[j]; bb[j-1]=max; if(max<dp[j]) max=dp[j]; } bb[j-1]=max; } printf("%d\n",max); } return 0; }
[/code]
相关文章推荐
- sicily 9562 SUME
- 收到推送发送通知到通知栏点击后启动应用
- Poj 1753
- HDU——5037——Frog
- 文章标题
- PHP开发环境——Zend Studio 12.5.1(64位)破解汉化
- sicily 9456 Clumsy Cows
- android杂项记录
- 【C#/算法】任意圆形和三角形相交部分面积的计算方法
- Redis之跳跃表SkipList
- android两种方式生成keystore
- man .info .--help的用法和区别
- html5中关于音频--视频的播放
- instanceType和id的异同
- java线程的学习
- 录音计时的TimeView
- c++从入门到实践
- 贤者时间太久了么?--MySQL继续玩
- 如何赚取人生的第一桶金
- MVC 学习 区域