题目传送门

 /*
题意:选择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. 解决Coldfusion连接MySQL数据库的问题

    在连接MySQL时,出现了如下错误: Connections to MySQL Community Server are not supported. Please contact MySQL to ...

  2. 系统重装 Ghost系统的disk to image等等是什么意思

    localdiskto disk to imade from imagepartitionto partition to image from imagecheckimage file disk这些是 ...

  3. 在XX公司工作第二天,维护已有代码

    根据<C++ More Exception>所述的规则: Rule #1: Never write using-directives in header files. Rule #2: N ...

  4. Unity UGUI——概述、长处

    Unity4.6推出的新UI系统 长处:灵活.高速.可视化.效率高效果好.易于使用和扩展

  5. C#建立最简单的web服务,无需IIS

    软件架构师何志丹 本程序仅仅是入门级程序.所以不考虑 1.多线程. 2,安全性. 3,不考虑端点下载文件. 4,Keep-Alive. 5,不考虑head. 6,为了简洁,删掉了catch的内容. e ...

  6. 在matlab中生成m序列

    实验环境为matlab2013b 1.首先编写一个mseq.m文件,内容为: function[mseq]=m_sequence(fbconnection)  n=length(fbconnectio ...

  7. 2016/3/13 MySQL 增删查改 CRUD 用代码实现

    用代码实现数据库数据输入 T-SQL语句 查询语句分几块 ①创建表 create table Car (Code varchar(50) primary key, #primary key 主键 定义 ...

  8. 【bzoj1071】[SCOI2007]组队

    sum= A*h+B*s排序 然后枚举height和speed的最小值 然后用两个指针:先枚举speed最小值,然后一边枚举v的最小值一边查询符合条件的人数. #include<algorith ...

  9. Jackson 框架的高阶应用

    Jackson 是当前用的比较广泛的,用来序列化和反序列化 json 的 Java 的开源框架.Jackson 社 区相对比较活跃,更新速度也比较快, 从 Github 中的统计来看,Jackson ...

  10. vim插件:显示树形目录插件NERDTree安装 和 使用【转】

    本文转载自:https://my.oschina.net/VASKS/blog/388907 下载和配置 NERDTree插件的官方地址如下,可以从这里获取最新的版本 https://github.c ...