hdoj Max Sum Plus Plus 1024 (DP) m个连续数组最大和
来源:互联网 发布:程序员平均工资 编辑:程序博客网 时间:2024/06/06 04:42
Max Sum Plus Plus
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 22076 Accepted Submission(s): 7405
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
68HintHuge input, scanf and dynamic programming is recommended.//题意:给你一个m,n,然后给你n个数,表示让你从n个数中找出m个连续的数组使得他们的和最大。#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>#define INF 0x80000000using namespace std;int a[1000010];int b[1000010];int dp[1000010];int main(){int n,m,i,j,k;int mm;while(scanf("%d%d",&m,&n)!=EOF){for(i=1;i<=n;i++)scanf("%d",&a[i]);for(i=0;i<=n;i++){dp[i]=0;b[i]=0;}for(i=1;i<=m;i++){mm=INF;for(j=i;j<=n;j++){if(dp[j-1]>b[j-1])dp[j]=dp[j-1]+a[j];elsedp[j]=b[j-1]+a[j];b[j-1]=mm;if(mm<dp[j])mm=dp[j];}b[j-1]=mm;}printf("%d\n",mm);}return 0;}
0 0
- hdoj Max Sum Plus Plus 1024 (DP) m个连续数组最大和
- hdoj Max Sum Plus Plus Plus 1244 (DP)m个连续段的最大和
- HDOJ 1024 Max Sum Plus Plus 最大M字段和
- hdu 1024 Max Sum Plus Plus 一串数字中,m段连续数字最大和 滚动数组+dp
- 【HDU1024】Max Sum Plus Plus (m个不相交连续子列的最大和)
- HDU 1024 Max Sum Plus Plus(求m个不相交连续子序列最大和/01背包)
- 【HDU 1024】Max Sum Plus Plus(DP+滚动数组优化+最大m段字段之和)
- HDOJ-1024 Max Sum Plus Plus (最大M子段和问题)
- hdoj 1024 Max Sum Plus Plus(m个子段最大和)
- HDOJ-1024 Max Sum Plus Plus (最大M子段和问题)
- hdoj 1024 Max Sum Plus Plus(最大m子段和)=-=
- Hdoj 1024 Max Sum Plus Plus 【DP】
- hdu 1024 Max Sum Plus Plus(DP&最大连续和加强版)
- hdu 1024 Max Sum Plus Plus(dp && 最大m子段和)
- HDU 1024 Max Sum Plus Plus[dp](最大m子段和)
- HDU 1024 Max Sum Plus Plus(dp最大m子段和)
- HDU 1024 Max Sum Plus Plus【DP,最大m子段和】
- hdu 1024 最大M子段和 Max Sum Plus Plus(dp)(中等难度)
- 深度学习batchsize对结果的影响
- ubuntu安装jdk全过程-转
- EJB基础一 无状态会话BEAN使用
- fail to build phoneME Feature-转
- ubuntu Ethernet over USB only 1 min discontent
- hdoj Max Sum Plus Plus 1024 (DP) m个连续数组最大和
- android 使用OkHttp上传多张图片
- Activity四种启动模式介绍
- 深入理解select网络模型(linux/windows)
- iOS 开发学习之 User Interface(1)APP 生命周期
- Volley框架
- SpannableString使用详解
- 【c/c++】auto()
- 利用python将夏普WG-S20输出的BMP转化成pdf并合并