美文网首页
2019-01-29HDU - 1024

2019-01-29HDU - 1024

作者: 林锦天 | 来源:发表于2019-01-29 17:35 被阅读0次

define _CRT_SECURE_NO_DEPRECATE

include<iostream>

include<stdio.h>

include<string.h>

include<cstring>

using namespace std;
long long num[120000], dp[120000], mk[120000];
long long maxx(long long x, long long y)
{
return x > y ? x : y;
}
int main()
{
int n, m, i, j;
while (~scanf("%d %d", &m, &n))
{
for (i = 1; i <= n; i++)
scanf("%I64d", &num[i]);

    long long max;
    for (i = 1; i <= m; i++)
    {
        max = -0x7ffffff;
        for (j = i; j <= n; j++)
        {
            if (i == j) dp[j] = mk[j - 1] + num[j];
            else
                dp[j] = maxx(dp[j - 1], mk[j - 1]) + num[j];
            mk[j - 1] = max;
            if (max < dp[j])max = dp[j];
        }
    }
   cout<<max;
    memset(dp, 0, sizeof(dp));
    memset(mk, 0, sizeof(mk));
}

}

相关文章

网友评论

      本文标题:2019-01-29HDU - 1024

      本文链接:https://www.haomeiwen.com/subject/lkgxsqtx.html