题目传送门

 /*
题意:选择k个m长的区间,使得总和最大
01背包:dp[i][j] 表示在i的位置选或不选[i-m+1, i]这个区间,当它是第j个区间。
01背包思想,状态转移方程:dp[i][j] = max (dp[i-1][j], dp[i-m][j-1] + sum[i] - sum[i-m]);
在两个for循环,每一次dp[i][j]的值都要更新
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std; typedef long long ll;
const int MAXN = 5e3 + ;
const int INF = 0x3f3f3f3f;
ll a[MAXN];
ll sum[MAXN];
ll dp[MAXN][MAXN]; int main(void) //Codeforces Round #267 (Div. 2) C. George and Job
{
int n, m, k;
while (scanf ("%d%d%d", &n, &m, &k) == )
{
memset (sum, , sizeof (sum));
for (int i=; i<=n; ++i) {scanf ("%I64d", &a[i]); sum[i] = sum[i-] + a[i];} ll ans = ;
for (int i=m; i<=n; ++i)
{
ll tmp = sum[i] - sum[i-m];
for (int j=; j<=k; ++j)
{
dp[i][j] = max (dp[i-][j], dp[i-m][j-] + tmp);
}
ans = max (ans, dp[i][k]);
} printf ("%I64d\n", ans);
} return ;
} /*
5 2 1
1 2 3 4 5
7 1 3
2 10 7 18 5 33 0
*/

01背包 Codeforces Round #267 (Div. 2) C. George and Job的更多相关文章

  1. Codeforces Round #267 (Div. 2) C. George and Job(DP)补题

    Codeforces Round #267 (Div. 2) C. George and Job题目链接请点击~ The new ITone 6 has been released recently ...

  2. Codeforces Round #267 (Div. 2) C. George and Job (dp)

    wa哭了,,t哭了,,还是看了题解... 8170436                 2014-10-11 06:41:51     njczy2010     C - George and Jo ...

  3. Codeforces Round #267 (Div. 2) C. George and Job DP

                                                  C. George and Job   The new ITone 6 has been released ...

  4. 完全背包 Codeforces Round #302 (Div. 2) C Writing Code

    题目传送门 /* 题意:n个程序员,每个人每行写a[i]个bug,现在写m行,最多出现b个bug,问可能的方案有几个 完全背包:dp[i][j][k] 表示i个人,j行,k个bug dp[0][0][ ...

  5. Codeforces Round #267 (Div. 2)

    A #include <iostream> #include<cstdio> #include<cstring> #include<algorithm> ...

  6. Codeforces Round #267 Div.2 D Fedor and Essay -- 强连通 DFS

    题意:给一篇文章,再给一些单词替换关系a b,表示单词a可被b替换,可多次替换,问最后把这篇文章替换后(或不替换)能达到的最小的'r'的个数是多少,如果'r'的个数相等,那么尽量是文章最短. 解法:易 ...

  7. Codeforces Round #267 (Div. 2) A

    题目: A. George and Accommodation time limit per test 1 second memory limit per test 256 megabytes inp ...

  8. Codeforces Round #267 (Div. 2)D(DFS+单词hash+简单DP)

    D. Fedor and Essay time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  9. Codeforces Round #267 (Div. 2) D. Fedor and Essay tarjan缩点

    D. Fedor and Essay time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. 安装软件:/lib/ld-linux.so.2: bad ELF interpreter解决

    http://linux.chinaitlab.com/set/928509.html 我们在CentOS系统中安装软件:/lib/ld-linux.so.2: bad ELF interpreter ...

  2. [javase学习笔记]-9.2 单继承与多重继承

    这一节我们来看java中的单继承和多重继承. 在java语言中,支持的是单继承,不直接支持多继承,可是对C++中的多继承进行了改良. 那么什么是单继承和多继承呢? 单继承:一个子类仅仅能有一个直接父类 ...

  3. [Angular] Refactor Angular Component State Logic into Directives

    Allow the base toggle to be a tag (<toggle>) or attribute (<div toggle>). The <toggle ...

  4. Angular2.x-服务

    heroes之旅HeroesComponent目前正在获取并显示虚假数据. 在本教程重构之后,HeroesComponent将会精益求精并专注于支持视图.用模拟服务进行单元测试也会更容易. 为什么服务 ...

  5. HDU 5288(OO’s Sequence-区间互质情况统计)

    OO's Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  6. Linux-github 搭建静态博客

    1.在Github上创建一个新的Repository 到你的github上 https://github.com去create a new repository命名为 github.myblog 2. ...

  7. 百万级PHP网站Poppen.de的架构分享心得

    在了解过世界最大的PHP站点,Facebook的后台技术后, 今天我们来了解一个百万级PHP站点的网站架构:Poppen.de.Poppen.de是德国的一个社交网站,相对Facebook.Flick ...

  8. Use Local Or Global Index?

    常常我们须要将大表依据分区键进行分区,当建立索引的时候.我们究竟使用local 还是global 索引呢 先看看两种索引的特点: 本地索引特点: 1. 本地索引一定是分区索引.分区键等同于表的分区键. ...

  9. Java基础面试:集合、内部类、线程

    package test; import java.util.Hashtable; import java.util.Map; public class test { public static St ...

  10. IDEA失效的解决办法

    1.根据下图进行操作即可解决