标签:des style http java color os strong io
1 3 1 2 3 2 6 -1 4 -2 3 -2 3
6 8
求区间的和。。DP题。。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
typedef __int64 LL;
using namespace std;
const int N=1000000+100;
const int INF = 0x3f3f3f3f;
LL a[N];
LL b[N];
LL dp[N];
LL Max;
int main()
{
int m, n;
while(scanf("%d%d", &m, &n)==2)
{
b[0] = dp[0] = 0;
for(int i=1; i<=n; i++)
{
scanf("%I64d", a+i);
b[i] = dp[i] = 0;
}
for(int i=1, j; i<=m; i++)
{
Max = -INF;
for(j=i; j<=n; j++)
{
if(b[j-1]>dp[j-1])
dp[j] = b[j-1] + a[j];
else
dp[j]=dp[j-1]+a[j];
b[j-1] = Max;
if(dp[j]>Max) Max = dp[j];
}
b[j-1] = Max;
}
printf("%I64d\n",Max);
}
return 0;
}
HDU 1024:Max Sum Plus Plus,布布扣,bubuko.com
标签:des style http java color os strong io
原文地址:http://blog.csdn.net/u013487051/article/details/38253559