题意:求一个数组中 M 段的 最大和
没看明白怎么搞得
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = + ;
int dp[N], num[N], pre[N];
int main()
{
int m, n;
while (scanf("%d%d", &m, &n) != EOF)
{
for (int i = ; i <= n; i++)
{
scanf("%d", &num[i]);
}
memset(pre, , sizeof(pre));
memset(dp, , sizeof(dp));
int ans = -INF, maxn;
for (int i = ; i <= m; i++)
{
maxn = -INF;
for (int j = i; j <= n; j++)
{
dp[j] = max(dp[j - ], pre[j - ]) + num[j];
pre[j - ] = maxn;
maxn = max(maxn, dp[j]);
}
//if (ans < maxn)
// ans = maxn;
}
printf("%d\n", maxn);
} return ;
}