【CodeForces - 467C】George and Job(dp,思维)
题干:
The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the following problem at the work.
Given a sequence of n integers p1, p2, ..., pn. You are to choose k pairs of integers:
[l1, r1], [l2, r2], ..., [lk, rk] (1 ≤ l1 ≤ r1 < l2 ≤ r2 < ... < lk ≤ rk ≤ n; ri - li + 1 = m),
in such a way that the value of sum is maximal possible. Help George to cope with the task.
Input
The first line contains three integers n, m and k (1 ≤ (m × k) ≤ n ≤ 5000). The second line contains n integers p1, p2, ..., pn (0 ≤ pi ≤ 109).
Output
Print an integer in a single line — the maximum possible value of sum.
Examples
Input
5 2 1
1 2 3 4 5
Output
9
Input
7 1 3
2 10 7 18 5 33 0
Output
61
题目大意:
给定n,m,k。求k个子段,每一段的长度是m,且每一段均要求不相交。求选中段的最大和。
解题报告:
直接dp[i][j]代表前i个数,分成j个子段,的最大和,然后转移即可。
也可以定义成dp[i][j]代表以第i个数为结尾,分成j个子段的最大和,这样的话需要枚举上一个断点,不过可以用一个数组预处理前缀最大值,所以复杂度是一样的,都可解。
AC代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define FF first
#define SS second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e5 + 5;
ll a[MAX],sum[MAX],dp[5005][5005],n,m,k;
int main()
{cin>>n>>m>>k;for(int i = 1; i<=n; i++) scanf("%lld",a+i);for(int i = 1; i<=n; i++) sum[i] = sum[i-1] + a[i];for(int i = m; i<=n; i++) {for(int j = 1; j<=k; j++) {dp[i][j] = max(dp[i-1][j],dp[i-m][j-1] + sum[i]-sum[i-m]);}}printf("%lld\n",dp[n][k]);return 0 ;
}
【CodeForces - 467C】George and Job(dp,思维)相关推荐
- CodeForces - 467C George and Job(二维dp)
题目链接:点击查看 题目大意:给出n个数,现在要从中选取k段长度为m的不相交的子数列,问如何选择能使得覆盖的数之和最大 题目分析:读完题之和就感觉是个dp题,但不会呀,去看了题解才会的.. 因为要选取 ...
- CSP-S 2019————Emiya 家今天的饭————DP+思维
题解:本题主要考查DP+思维. 简要题意:一个矩阵,要求每行只选一个节点,每列选的节点不能超过所有选的节点的一半,不能不选,给出每个节点的选择方案数,求总方案数. 1.DP+思维: (1).维护每列已 ...
- CodeForces - 1312E Array Shrinking(区间dp)(通俗易懂)
CodeForces - 1312E Array Shrinking(区间dp) 题目链接: 没做出来,看了一下别人的题解,才A掉.但网上没发现一篇讲得比较易懂的题解,所以就准备写一篇再加上我自己的理 ...
- 【CodeForces 1253C --- Sweets Eating】DP
[CodeForces 1253C --- Sweets Eating]DP Description Tsumugi brought n delicious sweets to the Light M ...
- Ivan the Fool and the Probability Theory-Codeforces Round #594 (Div. 2)-C题(dp+思维)
Ivan the Fool and the Probability Theory-Codeforces Round #594 (Div. 2)-C题(dp+思维) time limit per tes ...
- Codeforces Round #459 (Div. 2) C 思维,贪心 D 记忆化dp
Codeforces Round #459 (Div. 2) C. The Monster 题意:定义正确的括号串,是能够全部匹配的左右括号串. 给出一个字符串,有 (.). ? 三种字符, ? 可以 ...
- codeforces 808 E. Selling Souvenirs (dp+二分+思维)
题目链接:http://codeforces.com/contest/808/problem/E 题意:最多有100000个物品最大能放下300000的背包,每个物品都有权值和重量,为能够带的最大权值 ...
- CodeForces - 1498D Bananas in a Microwave(思维+dp)
题目链接:点击查看 题目大意:给出 nnn 次操作,初始时有一个 k=0k=0k=0,每次操作抽象为三个数 txyt\ x\ yt x y,其中 xxx 可能为小数,可以选择一个 num∈[0,y]n ...
- Codeforces Round #727 (Div. 2) E. Game with Cards dp + 思维
传送门 文章目录 题意: 思路: 题意: 初始有左右手,上面各有一个数字为000的卡牌,每次都有一个新卡kik_iki,你可以将其放在左手或者右手,使两只手上的卡片范围在[ll,i,rl,i][l_ ...
最新文章
- PyTorch框架:(4)如何去构建数据
- 使用MyBatis简化枚举类值的存储和读取
- 字符串中子序列出现次数
- CORS 跨域-哪些操作受到同源限制
- java实现123n_java三线程交替打印123……n
- web入门,这些必须掌握!!!
- 【作者面对面问答】包邮送《Redis 5设计与源码分析》5本
- 关于C#winform程序运行无异常,在生成安装文件安装后提示水晶报表加载失败,系统找不到指定的路径的解决方法...
- nvidia TX2 CUDA yolov5环境搭建
- 根据sessionId获取Session对象
- 2019-0404视觉SLAM的学习第三讲01
- 变身吧,无人机:多种姿势可以选择,你喜欢X还是O?
- Matlab7.0安装教程
- 【开发神器】自动化测试、用 Apipost!
- 台式计算机英特尔时间同步,我电脑时间没法与Inter同步,?
- python冒泡算法_python冒泡算法
- html引入png不显示透明北京,完美解决透明png图片及透明png背景,兼容所有浏览器...
- Flash:一个TLF图文并貌的高级应用类
- CNN应用之性别、年龄识别
- webpack4 学习时打包图片时遇到的问题
热门文章
- 公司间交易学习笔记---概述
- 使用 Visual Studio 2005 Team System 进行单元测试并生成用于 Unit Test Framework 的源代码...
- [Leedcode][JAVA][第22题括号生成][DFS][BFS][动态规划]
- [Leedcode][JAVA][面试题 01.07][找规律][旋转数组]
- [Leetcode][JAVA][第1111题][栈思想]
- 幅值与峰峰值的计算_电厂振动测量、计算基础及汽轮机组振动标准!
- python抢货程序_Python自动化xpath实现自动抢票抢货代码示例
- python如何移动图片_python之详细图像仿射变换讲解(图像平移、旋转、缩放、翻转),一文就够了,赶紧码住...
- 介绍一个新鲜玩意 开源的杀毒软件
- kafka分区与分组原理_kafka 基本原理和概念