#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<math.h>
#include<set>
#define N 210
#define LL long long
using namespace std;
const int inf = 0x3f3f3f3f;
int a[1000010];
LL dp[1000010];
LL s[1000010];
int main()
{
int n, m;
while (scanf("%d%d", &m, &n) != EOF)
{
memset(dp, 0, sizeof(dp));
memset(s, 0, sizeof(s));
for (int i = 1; i <= n; i++)
{
scanf("%d", &a[i]);
}
LL tmp;
for (int i = 1; i <= m; i++)
{
tmp = -inf;
for (int j = i; j <= n; j++)
{
dp[j] = max(dp[j - 1], s[j - 1]) + a[j];//上一层的是[j-1];
s[j - 1] = tmp;//更新这一层
tmp = max(tmp, dp[j]);
}
}
printf("%lld\n", tmp);
}
return 0;
}
hdu1024
最新推荐文章于 2022-11-24 16:33:52 发布