码迷,mamicode.com
首页 > 其他好文 > 详细

最大m字段和 自写的板子^_^

时间:2019-11-16 21:10:18      阅读:54      评论:0      收藏:0      [点我收藏+]

标签:++i   algo   ios   cout   algorithm   typedef   string   cto   inf   

#include<map>
#include<set>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<iomanip>
#include<sstream>
#include<iostream>
#include<algorithm>
#define INF 0x3f3f3f3f3f3f3f
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define ll __int64
#define int ll
//typedef  long long ll;
typedef unsigned long long ull;
const int MAXN=1e6+10;
const int MOD=1e9+7;
const double eps=1e-6;
using namespace std;
//-------------------------------------------//
int a[MAXN],pre_max[MAXN],temp[MAXN];
signed main()
{
    int n,m;
    while(scanf("%lld%lld",&m,&n)!=EOF)
    {
        int ans=-INF;
        for(int i=0;i<=m;++i)pre_max[i]=-INF,temp[i]=-INF;
        for(int i=1; i<=n; ++i)scanf("%lld",&a[i]);//cout<<"?";
        for(int i=1; i<=n; ++i)
        {
            int temp1=0;
            for(int j=1; j<=min(m,i); ++j)//temp[j]=dp[i-1][j]
            {
                temp[j]=max(temp[j],temp1)+a[i];
                temp1=pre_max[j];
                pre_max[j]=max(pre_max[j],temp[j]);
            }
            ans=max(temp[m],ans);
            //cout<<dp[1][i]<<endl;
        }
        cout<<ans<<endl;
    }
    return 0;
}

 

最大m字段和 自写的板子^_^

标签:++i   algo   ios   cout   algorithm   typedef   string   cto   inf   

原文地址:https://www.cnblogs.com/megadeth/p/11873469.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!