P5124 Teamwork(DP)
题目:
解析:
动态规划,设\(f[i]\)表示到第\(i\)位的最大值,我们枚举i之前的j个位置\((j<k)\),记录一下这\(j+1\)个数(包括自己)的最大值\(mx\),转移方程就是\(f[i]=max(f[i],f[i-j-1]+mx\times (j+1))\)
代码:
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int n, m, num;
int a[N], f[N];
template<class T>void read(T &x) {
x = 0; int f = 0; char ch = getchar();
while (!isdigit(ch)) f |= (ch == '-'), ch = getchar();
while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
x = f ? -x : x;
return;
}
int main() {
read(n), read(m);
for (int i = 1; i <= n; ++i) read(a[i]);
for (int i = 1; i <= n; ++i) {
int mx = -1;
f[i] = f[i - 1] + a[i];
for (int j = 0; j < m && i - j > 0; ++j) {
mx = max(mx, a[i - j]);
f[i] = max(f[i], f[i - j - 1] + mx * (j + 1));
}
}
cout << f[n];
}
P5124 Teamwork(DP)的更多相关文章
- 2019 GDUT Rating Contest I : Problem B. Teamwork
题面: 传送门 B. Teamwork Input file: standard input Output file: standard output Time limit: 1 second Memor ...
- BZOJ 1911: [Apio2010]特别行动队 [斜率优化DP]
1911: [Apio2010]特别行动队 Time Limit: 4 Sec Memory Limit: 64 MBSubmit: 4142 Solved: 1964[Submit][Statu ...
- 2013 Asia Changsha Regional Contest---Josephina and RPG(DP)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4800 Problem Description A role-playing game (RPG and ...
- AEAI DP V3.7.0 发布,开源综合应用开发平台
1 升级说明 AEAI DP 3.7版本是AEAI DP一个里程碑版本,基于JDK1.7开发,在本版本中新增支持Rest服务开发机制(默认支持WebService服务开发机制),且支持WS服务.RS ...
- AEAI DP V3.6.0 升级说明,开源综合应用开发平台
AEAI DP综合应用开发平台是一款扩展开发工具,专门用于开发MIS类的Java Web应用,本次发版的AEAI DP_v3.6.0版本为AEAI DP _v3.5.0版本的升级版本,该产品现已开源并 ...
- BZOJ 1597: [Usaco2008 Mar]土地购买 [斜率优化DP]
1597: [Usaco2008 Mar]土地购买 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 4026 Solved: 1473[Submit] ...
- [斜率优化DP]【学习笔记】【更新中】
参考资料: 1.元旦集训的课件已经很好了 http://files.cnblogs.com/files/candy99/dp.pdf 2.http://www.cnblogs.com/MashiroS ...
- BZOJ 1010: [HNOI2008]玩具装箱toy [DP 斜率优化]
1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 9812 Solved: 3978[Submit][St ...
- px、dp和sp,这些单位有什么区别?
DP 这个是最常用但也最难理解的尺寸单位.它与“像素密度”密切相关,所以 首先我们解释一下什么是像素密度.假设有一部手机,屏幕的物理尺寸为1.5英寸x2英寸,屏幕分辨率为240x320,则我们可以计算 ...
随机推荐
- jQuery之概念以及基本使用
1. jQuery的概述 1.1 jQuery的概念 jQuery是一个快速.简洁的JavaScript库,其设计的宗旨是“Write Less,Do More” jQuery主要是封装了JavaSc ...
- js addEventListener事件多次绑定问题
如果为了避免 js addEventListener事件多次绑定问题,可以使用.onclick直接绑定,后一次click绑定会覆盖调前一次.
- 推荐一款适合Dynamics 365/Dynamics CRM 2016 使用的弹出窗插件AlertJs
Github地址: https://github.com/PaulNieuwelaar/alertjs 目前有两个版本,3.0版本(30天免费试用)以及2.1版本(完全免费) ------------ ...
- 本地Yum源配置
一.网络源 yum list 软件名称 查找源里的软件,可以使用通配符 二.配置源 源配置文件路径 /etc/yum.repos.d/ 配置项 [名称] 源标识(不能和其他的源重复) name=名称 ...
- WC 个人项目 ( node.js 实现 )
基于 node.js 的 wordCounter 个人项目 GitHub 项目地址:https://github.com/KofeChen/node.js-WordCounter 实现功能: 能够匹配 ...
- [转]Eclipse插件开发之基础篇(4) OSGi框架
原文地址:http://www.cnblogs.com/liuzhuo/archive/2010/08/18/eclipse_plugin_1_2_1.html 1. 什么是OSGi框架 OSGi(O ...
- BayaiM__ORACLE之ASM概念 --V 1.0.0
BayaiM__ORACLE之ASM概念 --V 1.0.0 -------------------------------------- ...
- mysql使用命令
1.创建用户 create user 'name'@'host' identified by 'psssword'; 2.授权 grant select, updata,insert (all) on ...
- 19.Java基础_封装概念
- SQL(一)简介
select * from websites 使用的sql为: /* Navicat MySQL Data Transfer Source Server : 127.0.0.1 Source Serv ...