记录编号 201191 评测结果 AAAAAAAAAA
题目名称 [ZLXOI 2015][异次元圣战II]燃灵之链 最终得分 100
用户昵称 Gravatardevil 是否通过 通过
代码语言 C++ 运行时间 0.047 s
提交时间 2015-10-30 08:49:00 内存使用 0.32 MiB
显示代码纯文本
#include <cstdlib>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <stack>
#include <vector>
#include <map>
#include <queue>
#include <ctime>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int uint;
const int inf=1061109567;
const int maxn=1010;
const int maxm=1010;
const int mod=1000000007;

int f[maxn];
int g[maxn];

int main()
{
    freopen("KPengshuangcang.in","r",stdin);
    freopen("KPengshuangcang.out","w",stdout);
    //clock_t st=clock();
    int n,k,a;scanf("%d%d",&n,&k);
    for(int i=1;i<=k;i++) f[i]=g[i]=-inf;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a);
        for(int j=min(i,k);j>=1;j--)
        {
            g[j]=max(f[j],g[j]);
            f[j]=max(f[j],g[j-1])+a;
        }
    }
    printf("%d\n",max(f[k],g[k]));
    //clock_t ed=clock();
    //printf("\nTime used : %.5lf Ms\n",double(ed-st)/CLOCKS_PER_SEC);
    return 0;
}