HDU 1024

参考:http://www.cnblogs.com/kuangbin/archive/2011/08/04/2127085.html


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int dp[100005],data[100005],Max[1000005],predp,mmax;
int main(){
    int n,m;
    while(scanf("%d%d",&m,&n)!=EOF){
        Max[0]=dp[0]=0;
        for(int i=1;i<=n;i++) {
            scanf("%d",&data[i]);
            dp[i]=0;
            Max[i] = 0;
        }
        predp=0;
        for(int i=1;i<=m;i++) {
            //printf("%d %d\n",Max[i-1],predp);
            mmax = -9999999;
            for(int j=i;j<=n;j++) {
                dp[j] = max(predp,Max[j-1]) + data[j];
                predp = dp[j];
                Max[j-1] = mmax;
                mmax = max(mmax,dp[j]);
            }
            predp = dp[i]; 
        }
        printf("%d\n",mmax);
    }
}


你可能感兴趣的:(dp)