[ABC261D] Flipping and Bonus
Problem Statement
Takahashi will toss a coin $N$ times.
He also has a counter, which initially shows $0$.
Depending on the result of the $i$-th coin toss, the following happens:
- If it heads: Takahashi increases the counter's value by $1$ and receives $X_i$ yen (Japanese currency).
- If it tails: he resets the counter's value to $0$, without receiving money.
Additionally, there are $M$ kinds of streak bonuses. The $i$-th kind of streak bonus awards $Y_i$ yen each time the counter shows $C_i$.
Find the maximum amount of money that Takahashi can receive.
Constraints
- $1\leq M\leq N\leq 5000$
- $1\leq X_i\leq 10^9$
- $1\leq C_i\leq N$
- $1\leq Y_i\leq 10^9$
- $C_1,C_2,\ldots,C_M$ are all different.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
$N$ $M$
\(X_1\) \(X_2\) \(\ldots\) \(X_N\)
\(C_1\) \(Y_1\)
\(C_2\) \(Y_2\)
\(\vdots\)
\(C_M\) \(Y_M\)
Output
Print the maximum amount of money that Takahashi can receive, as an integer.
Sample Input 1
6 3
2 7 1 8 2 8
2 10
3 1
5 5
Sample Output 1
48
If he gets head, head, tail, head, head, head, in this order, the following amounts of money are awarded.
- In the $1$-st coin toss, the coin heads. Change the counter's value from $0$ to $1$ and receive $2$ yen.
- In the $2$-nd coin toss, the coin heads. Change the counter's value from $1$ to $2$ and receive $7$ yen. Additionally, get $10$ yen as a streak bonus.
- In the $3$-rd coin toss, the coin tails. Change the counter's value from $2$ to $0$.
- In the $4$-th coin toss, the coin heads. Change the counter's value from $0$ to $1$ and receive $8$ yen.
- In the $5$-th coin toss, the coin heads. Change the counter's value from $1$ to $2$ and receive $2$ yen. Additionally, get $10$ yen as a streak bonus.
- In the $6$-th coin toss, the coin heads. Change the counter's value from $2$ to $3$ and receive $8$ yen. Additionally, get $1$ yen as a streak bonus.
In this case, Takahashi receives $2+(7+10)+0+8+(2+10)+(8+1)=48$ yen in total, which is the maximum possible.
Note that streak bonuses are awarded any number of times each time the counter shows $C_i$.
As a side note, if he gets head in all $6$ coin tosses, he only receives $2+(7+10)+(1+1)+8+(2+5)+8=44$ yen, which is not the maximum.
Sample Input 2
3 2
1000000000 1000000000 1000000000
1 1000000000
3 1000000000
定义\(dp_{i,j}\)为扔了 \(i\) 次硬币 counter 为 \(j\) 的最大收钱数。
设 counter 达到 \(k\) 时收到 \(t_k\) 日元。
如果 \(j\ne 0\),那么 \(dp_{i,j}=dp_{i-1,j-1}+X_i+t_j\)
如果 \(j=0\) 为 0,\(dp_{i,j}=\max\limits_{j=0}^{n-1}dp_{i-1,j}\)
#include<bits/stdc++.h>
using namespace std;
const int N=5005;
int x[N],c,y,t[N],n,m;
long long dp[N][N],ans;
int main()
{
memset(dp,-0x7f,sizeof(dp));
dp[0][0]=0;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
scanf("%d",x+i);
for(int i=1;i<=m;i++)
scanf("%d%d",&c,&y),t[c]+=y;
for(int i=1;i<=n;i++)
{
dp[i][0]=dp[i-1][0];
for(int j=1;j<=n;j++)
dp[i][j]=dp[i-1][j-1]+t[j]+x[i],dp[i][0]=max(dp[i][0],dp[i-1][j-1]),ans=max(ans,dp[i][j]);
}
printf("%lld",ans);
}
[ABC261D] Flipping and Bonus的更多相关文章
- Flipping elements with WPF
http://yichuanshen.de/blog/2010/11/13/flipping-elements-with-wpf/ Have you already seen ForgottenTim ...
- ZOJ3762 The Bonus Salary!(最小费用最大流)
题意:给你N个的任务一定要在每天的[Li,Ri]时段完成,然后你只有K天的时间,每个任务有个val,然后求K天里能够获得的最大bonus. 思路:拿到手第一直觉是最小费用最大流,然后不会建图,就跑去想 ...
- Codeforces Gym 100803G Flipping Parentheses 线段树+二分
Flipping Parentheses 题目连接: http://codeforces.com/gym/100803/attachments Description A string consist ...
- 【OpenMesh】Some basic operations: Flipping and collapsing edges
这一节中你将学到一些OpenMesh中早已提供的基础操作. 内容包括三角形网格边的翻转以及通过连接邻接的顶点边缘折叠. 三角形网格的翻转(Flipping edges) 考虑到两个邻接面的三角形网格中 ...
- Flipping Game(枚举)
Flipping Game time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #191 (Div. 2)---A. Flipping Game
Flipping Game time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- veridata实验举例(2)验证表BONUS与表SALGRADE两节点同步情况
veridata实验举例(2)验证表BONUS与表SALGRADE两节点同步情况 续接前几篇文章: 1.GoldenGate配置(一)之单向复制配置 地址:点击打开链接 2.GoldenGate配置( ...
- Flipping Parentheses~Gym 100803G
Description A string consisting only of parentheses '(' and ')' is called balanced if it is one of t ...
- [LeetCode] Flipping an Image 翻转图像
Given a binary matrix A, we want to flip the image horizontally, then invert it, and return the resu ...
- [SQL]LeetCode577.员工奖金 | Employee Bonus
Select all employee's name and bonus whose bonus is < 1000. Table:Employee +-------+--------+---- ...
随机推荐
- 5、Mybatis之获取参数值
5.1.创建新module 5.1.1.右击SSM文件夹,创建新module 5.1.2.选择maven 5.1.3.配置module名称和路径 5.1.4.module初始状态 5.1.5.复制打包 ...
- PyAV 使用浅谈
背景: PyAV是一个用于音频和视频处理的Python库,它提供了一个简单而强大的接口,用于解码.编码.处理和分析各种音频和视频格式.PyAV基于FFmpeg多媒体框架,它本质上是FFmpeg 的Py ...
- Laf & 中大猫谱:让每一只流浪猫都有家
猫谱简介 中大猫谱是一款辅助校园流浪猫救助的开源小程序项目,服务端使用 Laf 云开发. 猫谱主要功能包括:猫咪信息登记.照片分享.拍照识猫.公告和留言等.项目创立的初衷,是解决校园猫猫交流群里的一个 ...
- 简单描述下HTTP协议和TCP协议之间的关系以及TCP三次握手, 四次挥手
TCP 三次握手, 四次挥手 TCP(传输控制协议)是一种用于在计算机网络中建立可靠连接的协议.TCP连接的建立和终止分别使用了"三次握手"和"四次挥手"的过程 ...
- 一篇关于获得拼多多商品详情 API的使用说明
拼多多(Pinduoduo)是中国一家快速发展的电商平台,为了帮助开发者更好地接入拼多多,平台提供了丰富的 API 接口供开发者使用,其中包括获取拼多多商品详情的 API.接下来,我们将介绍如何使用拼 ...
- webgl 刷底色的基本步骤
1.在html中建立画布 <canvas id="canvas"><canvas> 2.在js中获取canvas画布 const canvas = docu ...
- 在微服务环境下,远程调用feign和异步线程存在请求数据丢失问题
一.无异步线程得情况下feign远程调用: 0.登录拦截器: @Component public class LoginUserInterceptor implements HandlerInterc ...
- 在Docker下一键安装部署免费开源的问答社区!
在Docker下一键安装部署免费开源的问答社区! 1.准备一台VPS主机,没有的话,[搞一台] 2.一键安装部署Docker wget https://raw.githubusercontent. ...
- IL编制器 --- Fody
介绍 这个项目的名称"Fody"来源于属于织巢鸟科(Ploceidae)的小鸟(Fody),本身意义为编织. 核心Fody引擎的代码库地址 :https://github.com/ ...
- #866 div1A
A. Constructive Problem 题意:给定一个长度为n的非负数组a,我们可以进行一次操作,操作是将l~r这个区间内的所有数变为k(k >= 0),得到b,能不能使mex(a)+ ...