[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 +-------+--------+---- ...
随机推荐
- 【全新重构发布】iNeuOS工业互联网操作系统 V5 版本
iNeuOS工业互联网操作系统历经迭代27个版本,老版本截止更新V4.1版本:历时一年多时间,现在正式发布全新V5版本,V5版本与V4.1老版本不完全兼容. 发布V5版本后,iNeuOS工业互联网操作 ...
- 《Linux基础》05. 定时任务调度 · 磁盘分区与挂载 · 网络配置
@ 目录 1:定时任务调度 1.1:crontab 1.2:at 2:磁盘分区与挂载 2.1:原理介绍 2.2:硬盘说明 2.3:磁盘目录情况查询 2.3.1:lsblk 2.3.2:df 2.3.3 ...
- Java读取某个文件夹下的所有文件(支持多级文件夹)
源码如下: package com.vocy.water.batch; import java.io.FileNotFoundException; import java.io.IOException ...
- KRPANO开发拍摄拼图视频常用软件分享
KRPano开发拍摄拼图视频常用软件分享,包含了KRPano开发,拼图,视频等软件. 包括如下软件: 全景照片拼接,全景照片查看,全景视频拼接,全景视频查看,全景视频插件,全景漫游制作,KRPano资 ...
- 遥遥领先.NET 7, .NET 8 性能大幅提升
每个版本必有的性能提升汇总文章又来了.大家可以学习阅读了. 微软 .NET 开发团队的工程师 Stephen Toub 发表博客<Performance Improvements in .NET ...
- python入门基础(13)--类、对象
面向过程的编程语言,如C语言,所使用的数据和函数之间是没有任何直接联系的,它们之间是通过函数调用提供参数的形式将数据传入函数进行处理. 但可能因为错误的传递参数.错误地修改了数据而导致程序出错,甚至是 ...
- Journey / Solution Set - 「NOIP-S 2020」「Prob. A-C」
这种东西怎么写啊... Day 1(好像也没有 Day 2 到了 NK 后发现正好可以进门,于是就什么也没有检查的进去了. 进门前问了一下 LYC 之前问过的一个问题,他说没有头绪,然后就没怎么说话了 ...
- 兴达易控modbus转profinet网关与温度变送器兼容转modbus tcp网口协议
兴达易控modbus转profinet网关与流量变送器兼容转modbusTCP网口协议 本案例演示电磁流量计通过兴达易控modbus转profinet网关(XD-MDPN100)连接西门子1200PL ...
- HOMER7配置告警
概述 HOMER是一款100%开源的针对SIP/VOIP/RTC的抓包工具和监控工具. HOMER是一款强大的.运营商级.可扩展的数据包和事件捕获系统,是基于HEP/EEP协议的VoIP/RTC监控应 ...
- 高效数据管理:Java助力实现Excel数据验证
摘要:本文由葡萄城技术团队原创并首发.转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 前言 在Java中,开发者可以使用一些开源的库(如Apache POI ...