hdoj 1024 Max Sum Plus Plus 【简单dp】
来源:互联网 发布:算法精解怎么样知乎 编辑:程序博客网 时间:2024/06/05 06:27
Max Sum Plus Plus
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 21561 Accepted Submission(s): 7227
Problem Description
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. ^_^
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. ^_^
Input
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.
Process to the end of file.
Output
Output the maximal summation described above in one line.
Sample Input
1 3 1 2 32 6 -1 4 -2 3 -2 3
Sample Output
68分析:最大区域子段和问题代码:#include<cstdio>#include<cstring>#include<cstdlib>#include<queue>#include<algorithm>#include<stack>#define mem(x,y) memset(x,y,sizeof(x))#define max(a,b) a>b?a:b#define min(a,b) a<b?a:b#define inf 0x80000000using namespace std;const int N=1e6+10;int pp[N],dp[N],bb[N];int main(){ int n,m,i,j,k,mmax; 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++) { mmax=inf; 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]=mmax; if(mmax<dp[j]) mmax=dp[j]; } bb[j-1]=mmax; //printf("%d\n",bb[j-1]); } printf("%d\n",mmax); } return 0;}
0 0
- hdoj 1024 Max Sum Plus Plus 【简单dp】
- Hdoj 1024 Max Sum Plus Plus 【DP】
- HDOJ 1024 Max Sum Plus Plus
- hdoj 1024 Max Sum Plus Plus
- HDOJ 1024 Max Sum Plus Plus
- HDOJ-1024 Max Sum Plus Plus
- HDOJ 1024 Max Sum Plus Plus
- HDOJ HDU 1024 Max Sum Plus Plus
- hdu 1024 Max Sum Plus Plus--DP
- hdu 1024 Max Sum Plus Plus(dp)
- hdu-1024-Max Sum Plus Plus-DP
- hdu 1024 Max Sum Plus Plus(dp)
- hdu 1024 Max Sum Plus Plus dp
- HDU DP - 1024 Max Sum Plus Plus
- HDU 1024 Max Sum Plus Plus【DP】
- HDU 1024 Max Sum Plus Plus(DP)
- HDU 1024 Max Sum Plus Plus DP
- HDU 1024 Max Sum Plus Plus DP *
- 数组和指针的区别
- Java垃圾回收机制
- 【IOS】iphone6s 3d touch之HelloWorld
- Elasticsearch[2.0] ☞ Java Client API ☞ Percolate API
- 调用照相机和相册功能
- hdoj 1024 Max Sum Plus Plus 【简单dp】
- 蓝桥杯基础练习 回文数
- iOS问题总结
- Adb failed to restart! Make sure the plugin is properly configured.
- excel排序---结构体的排序
- 图论算法基础
- Python编写微信打飞机小游戏(十)
- Python核心数据类型——元祖、文件及其他
- Android 百度地图SDK 实现获取周边位置POI