Cod sursa(job #2471219)

Utilizator TheNextGenerationAyy LMAO TheNextGeneration Data 10 octombrie 2019 16:45:06
Problema Ferma Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <bits/stdc++.h>

using namespace std;
ifstream in("ferma.in");
ofstream out("ferma.out");
const int N = 10005;
const int K =  1005;
int dp[2][N][K],v[N];

int main()
{
    int n,k;
    in >> n >> k;
    k++;
    for (int i = 1; i<=n; i++)
        in >> v[i];
    for (int i = 1; i<=n; i++)
        for (int j = 1; j<=k; j++)
        {
            dp[1][i][j] = v[i]+max(dp[1][i-1][j],dp[0][i-1][j-1]);
            dp[0][i][j] = max(dp[1][i-1][j],dp[0][i-1][j]);
        }
    out << max(0,dp[1][n][k]);
}