当前位置:网站首页>ABC 261.D - Flipping and Bonus ( DP )
ABC 261.D - Flipping and Bonus ( DP )
2022-07-25 05:31:00 【Vijurria】
问题陈述
抛硬币N次,有一个计数器,最初显示为0。根据第i次抛硬币的结果,会发生以下情况:
如果它是正面的:将计数器的值增加1并得到Xi;
如果它是反面的:将计数器的值设为0(不加Xi)。
此外,有M种连胜奖金。求能收到的最大金额。
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.(头头尾头头头)
- 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操作:2+(7+10)+0+8+(2+10)+(8+1)=48
注意二维数组长度!
//#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]共抛出i次且计数器为j
for(int i=1;i<=n;i++)//共抛了i次硬币
{
for(int j=1;j<=i;j++)//计数器为j
{
//让当前所抛出的硬币通通体验一下处于什么位置时候的值
f[i][j]=f[i-1][j-1]+a[i]+mp[j];
}
f[i][0]=0;
for(int k=1;k<i;k++)
{
//记录上一行操作下能够得到的最大的值
//放在第0个的位置是为了满足上边当计数器为1的时候
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;
}边栏推荐
猜你喜欢

50:第五章:开发admin管理服务:3:开发【查询admin用户名是否已存在,接口】;(这个接口需要登录时才能调用;所以我们编写了拦截器,让其拦截请求,判断用户是否是登录状态;)

项目管理工具——项目开发者工具

微服务及相关组件概念

Panda3D keyboard moving scene

Basset: learning the regulatory code of the accessible genome with deep convolutional neural network

Microservice - remote invocation (feign component)
![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

Three schemes for finclip to realize wechat authorized login

Wechat applet related operation examples

Leetcode 202. happy number (not happy at all)
随机推荐
单点登录(一处登录,处处可用)
ThreadLocal
微服务 - 网关Gateway组件
Leetcode 237. 删除链表中的节点
Performance Optimization: lazy loading of pictures
Basset: learning the regulatory code of the accessible genome with deep convolutional neural network
background
Odoo14 | about the abnormal display of statusbar keyword after use and Its Solutions
The third day of rhcsa summer vacation
Leetcode 202. happy number (not happy at all)
聊聊 Redis 是如何进行请求处理
uniapp手机端uView的u-collapse组件高度init
SystemVerilog中$write与$display区别
What about reinstalling win11 system?
Sword finger offer II 014. anagrams in strings
微服务 - Hystrix 熔断器
Microservice gateway component
Solution of win11 blue screen code 0x0000001a
Implement is by yourself_ class
LCP插件创建对等物理接口