zoukankan      html  css  js  c++  java
  • Codeforces 467C. George and Job (dp)

    题目链接:http://codeforces.com/contest/467/problem/C

    求k个不重叠长m的连续子序列的最大和。

    dp[i][j]表示第i个数的位置个序列的最大和。

    前缀和一下就好了。空间可以优化,滚动数组就好了。

     1 //#pragma comment(linker, "/STACK:102400000, 102400000")
     2 #include <algorithm>
     3 #include <iostream>
     4 #include <cstdlib>
     5 #include <cstring>
     6 #include <cstdio>
     7 #include <vector>
     8 #include <cmath>
     9 #include <ctime>
    10 #include <list>
    11 #include <set>
    12 #include <map>
    13 using namespace std;
    14 typedef long long LL;
    15 typedef pair <int, int> P;
    16 const int N = 5e3 + 5;
    17 LL dp[N][2];
    18 LL sum[N];
    19 
    20 int main()
    21 {
    22     int n, m, k;
    23     scanf("%d %d %d", &n, &m, &k);
    24     for(int i = 1; i <= n; ++i) {
    25         scanf("%lld", sum + i);
    26         sum[i] += sum[i - 1];
    27     }
    28     for(int j = 1; j <= k; ++j) {
    29         for(int i = m*j; i <= n; ++i) {
    30             dp[i][j%2] = max(dp[i - m][(j - 1)%2] + sum[i] - sum[i - m], dp[i - 1][j%2]);
    31         }
    32     }
    33     printf("%lld
    ", dp[n][k%2]);
    34     return 0;
    35 }
  • 相关阅读:
    奇偶数排序
    买房子
    首字母大写
    学分绩点
    加减乘除
    最简真分数
    Hdu 1058 Humble Numbers
    Hdu 1032 The 3n + 1 problem
    Hdu 1040 As Easy As A+B
    Hdu 1025 Constructing Roads In JGShining's Kingdom
  • 原文地址:https://www.cnblogs.com/Recoder/p/5912457.html
Copyright © 2011-2022 走看看