当前位置:网站首页>ABC 261.D - Flipping and Bonus ( DP )
ABC 261.D - Flipping and Bonus ( DP )
2022-07-25 05:33:00 【Vijurria】
Problem statement
Flip a coin N Time , There is a counter , Initially displayed as 0.According to the first i The result of the coin toss , The following will happen :
If it is positive : Increase the value of the counter 1 And get the Xi;
If it's the opposite : Set the value of the counter to 0( No addition Xi).
Besides , Yes M Winning streak bonus .Ask for the maximum amount you can receive .
Sample Input 1 Copy
6 3 2 7 1 8 2 8 2 10 3 1 5 5Sample Output 1 Copy
48If he gets head, head, tail, head, head, head, in this order, the following amounts of money are awarded.( Head and tail )
- 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 22 to 3 and receive 8 yen. Additionally, get 1 yen as a streak bonus.
max operation :2+(7+10)+0+8+(2+10)+(8+1)=48
Note the length of the two-dimensional array !
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cstdio>
#include<map>
#include<vector>
#include<set>
#include<queue>
#include<deque>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=200200;
const int M=5002;
const int mod=998244353;
LL a[N],f[M][M];
LL mp[N];
int b[N];
bool vis[N];
int dx[]={-1,0,0,1},dy[]={0,1,-1,0};
string s[N];
int main()
{
cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
int T=1;
//cin>>T;
while(T--)
{
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=m;i++)
{
LL x,y;
cin>>x>>y;
mp[x]=y;
}
//f[i][j] Co throw i Times and the counter is j
for(int i=1;i<=n;i++)// Throw it all i The second coin
{
for(int j=1;j<=i;j++)// The counter for j
{
// Let the coin thrown at present experience the value at what position
f[i][j]=f[i-1][j-1]+a[i]+mp[j];
}
f[i][0]=0;
for(int k=1;k<i;k++)
{
// Record the maximum value that can be obtained under the operation of the previous line
// Put it in the 0 The position of is to meet the above when the counter is 1 When
f[i][0]=max(f[i][0],f[i-1][k]);
}
}
/*for(int i=0;i<=n;i++)
{
for(int j=0;j<=n;j++)
{
cout<<f[i][j]<<" ";
}
cout<<endl;
}*/
LL maxn=0;
for(int i=1;i<=n;i++)
maxn=max(maxn,f[n][i]);
cout<<maxn<<endl;
}
return 0;
}边栏推荐
猜你喜欢

Microservice configuration center Nacos

AirServer 7.3.0中文版手机设备无线传送电脑屏幕工具

Talk about how redis handles requests

Leetcode 237. 删除链表中的节点

微服务 - 远程调用(Feign组件)

How to carry out the function test with simple appearance and complex interior?

Realsense D435i 深度图优化_高精度模式

RHCE first day

自己实现is_class
![50: Chapter 5: develop admin management service: 3: develop [query whether the admin user name already exists, interface]; (this interface can only be called when logging in; so we have written an int](/img/1b/b8529b6f1d163a9e5d5dad2b78ce93.png)
50: Chapter 5: develop admin management service: 3: develop [query whether the admin user name already exists, interface]; (this interface can only be called when logging in; so we have written an int
随机推荐
Introduction summary of using unirx in unity
ping命令
I have seven schemes to realize web real-time message push, seven!
Implement is by yourself_ class
background
STL notes (IV): String
Three billion dollars! Horizon becomes the world's highest valued AI chip Unicorn
Microservices and related component concepts
Unity accesses chartandgraph chart plug-in
ThreadLocal
Microservice - hystrix fuse
JWT(json web token)
Implement is by yourself_ base_ of
Leetcode 204. 计数质数(太妙了)
Which side of Nacos has the SQL script of this column?
obj文件格式与.mtl文件格式
What content does the software test plan include and how to write it. Share test plan template
OpenFegin远程调用丢失请求头问题
单点登录(一处登录,处处可用)
Easyrecovery free data recovery tool is easy to operate and restore data with one click