hdu 1024 DP
#include <iostream>
using namespace std;
const int MAXN = 1000010;
__int64 dp[MAXN][2];
int n, m;
__int64 array[MAXN];
inline __int64 MAX(__int64 a, __int64 b)
{
return a > b ? a : b;
}
int main()
{
while (scanf("%d %d", &m, &n) != EOF)
{
int i, j;
for (i = 1; i <= n; ++i)
{
scanf("%I64d", &array[i]);
}
m = m > n ? n : m;
for (i = 0; i <= n; ++i)
{
dp[i][0] = 0;
}
__int64 _max;
for (i = 1; i <= m; ++i)
{//dp[i][k] = max(dp[i-1][k], max{dp[j][k-1]|(k-1<=j<i)}) + array[i]
dp[i][1] = dp[i-1][0] + array[i];
_max = dp[i][1];
for (j = i+1; j <= n-m+i; ++j)
{
dp[j][1] = MAX(dp[j-1][1], dp[j-1][0]) + array[j];
dp[j-1][0] = _max;
_max = MAX(_max, dp[j][1]);
}
dp[j-1][0] = _max;
}
printf("%I64d\n", dp[n][0]);
}
return 0;
}