题目传送门

 /*
题意:选择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. CentOS 5 全功能服务器搭建

    转自: http://www.php-oa.com/2007/12/27/centos-www.html 转:主要做为历史记录,以后用.另外很少见这么好的编译的文章,其实我不推荐用编译安装.但这个文章 ...

  2. Direct Buffer vs. Heap Buffer

    1. 劣势:创建和释放Direct Buffer的代价比Heap Buffer得要高. 2. 差别:Direct Buffer不是分配在堆上的,它不被GC直接管理(但Direct Buffer的JAV ...

  3. 微信小程序之 页面跳转 及 调用本地json的假数据调试

    一.微信小程序 跳转页面 小程序页面有2种跳转,可以在wxml页面或者js中: (1)在wxml页面中: <navigator url="../index/index"> ...

  4. java实现从报文中获取投保单号

    java实现从报文中获取投保单号 投保单号正则表达式: String regex = "<proposalNo>([0-9]+)</proposalNo>[\\s\\ ...

  5. 远程调试 Asp.Net 项目

    项目部署到产品环境后,难免会发生一些故障,有一些可以在本地测试环境中直接重现,而有一些则无法重现.对于可以在本地测试环境中重现的Bug,开发人员往往能够很迅速地进行问题排查.而对于无法重现的Bug,就 ...

  6. 【STORAGE】Qlogic FC存储交换机cmd配置方法

    *************************************************************** ****原文: blog.csdn.net/clark_xu  徐长亮专 ...

  7. Oracle常用SQL与练习

    基本 数学函数 rownum相关 分页查询 (假设每页显示10条) 不包含排序: 包含排序: 时间处理 1. to_char和to_date基本使用 eg1: eg2: 2)months_betwee ...

  8. 从sp_executesql中返回table型数据及动态SQL语句的参数化查询

    在返回分页数据时,我们会经常会用到参数化传递过滤条件,如何拼接SQL语句成了一个难题. 我们可以这样拼接: exec('sp_executesql sql语句,参数定义,参数值') sql语句和参数定 ...

  9. EF3:Entity Framework三种开发模式实现数据访问

    前言 Entity Framework支持Database First.Model First和Code Only三种开发模式,各模式的开发流程大相径庭,开发体验完全不一样.三种开发模式各有优缺点,对 ...

  10. 并不对劲的p2664树上游戏

    题目大意 有一棵\(n\)(\(n\leq10^5\))个点的树,每个点\(i\)有颜色\(c_i\)(\(c_i\leq10^5\)) 定义一条路径的得分为这条路径上的不同颜色个数 分别求每个点的以 ...