标签:++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; }
标签:++i algo ios cout algorithm typedef string cto inf
原文地址:https://www.cnblogs.com/megadeth/p/11873469.html