Educational Codeforces Round 20 E - Roma and Poker(dp)
传送门
题意
Roma在玩一个游戏,一共玩了n局,赢则bourle+1,输则bourle-1,Roma将会在以下情况中退出
1.他赢了k个bourle
2.他输了k个bourle
现在给出一个字符串
'L':lose
'W':win
'?':任意
'D':平局
输出一个字符串满足条件(Roma n局后离开要满足上述两个其中之一)
分析
dp题
令dp[i][j]表示进行i-1局比赛后,是否获得j个bourle。
如果第i局为'W': dp[i+1][j+1]=j;
如果第i局为'L':dp[i+1][j-1]=j;
如果第i局为'D':dp[i+1][j]=j;
如果第i局为'?':上面三个都要进行
一开始dp[0][1500]=0
最后从n-1到0,比较dp[i][f]与f,f一开始是1500±k,f=dp[i+1][f]
回溯判断输出
trick
代码
#include<cstdio>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
string s;
int dp[1010][3030];
int n,k;
int main()
{
cin>>n>>k>>s;
for(int i=0;i<1010;++i)for(int j=0;j<3030;++j) dp[i][j]=-1;
dp[0][1500]=0;
for(int i=0;i<n;++i)
for(int j=1500-k+1;j<=1500+k-1;++j)
{
if(dp[i][j]==-1)continue;
if(s[i]=='W'||s[i]=='?') dp[i+1][j+1]=j;
if(s[i]=='L'||s[i]=='?') dp[i+1][j-1]=j;
if(s[i]=='D'||s[i]=='?') dp[i+1][j]=j;
}
if(dp[n][1500+k]==-1&&dp[n][1500-k]==-1) { puts("NO");return 0; }
int f=1500+k;
if(dp[n][1500+k]==-1) f=1500-k;
for(int i=n-1;i>=0;--i)
{
int g=f;f=dp[i+1][f];
if(g-f==1) s[i]='W';
if(g-f==0) s[i]='D';
if(g-f==-1) s[i]='L';
}
cout<<s<<endl;
return 0;
}
Educational Codeforces Round 20 E - Roma and Poker(dp)的更多相关文章
- Educational Codeforces Round 16 E. Generate a String (DP)
Generate a String 题目链接: http://codeforces.com/contest/710/problem/E Description zscoder wants to gen ...
- Educational Codeforces Round 22 B. The Golden Age(暴力)
题目链接:http://codeforces.com/contest/813/problem/B 题意:就是有一个数叫做不幸运数,满足题目的 n = x^a + y^b,现在给你一个区间[l,r],让 ...
- D Merge Equals Educational Codeforces Round 42 (Rated for Div. 2) (STL )
D. Merge Equals time limit per test2 seconds memory limit per test256 megabytes inputstandard input ...
- Educational Codeforces Round 54 [Rated for Div. 2] (CF1076)
第一次在宿舍打CF 把同宿舍的妹子吵得不行... 特此抱歉QAQ A 题意:给定一个字符串, 最多删掉一个字符,使得剩余字符串字典序最小 n<=2e5 当然"最多"是假的 删 ...
- Educational Codeforces Round 32:E. Maximum Subsequence(Meet-in-the-middle)
题目链接:E. Maximum Subsequence 用了一个Meet-in-the-middle的技巧,还是第一次用到这个技巧,其实这个技巧和二分很像,主要是在dfs中,如果数量减小一半可以节约很 ...
- Codeforces Round #471 (Div. 2) F. Heaps(dp)
题意 给定一棵以 \(1\) 号点为根的树.若满足以下条件,则认为节点 \(p\) 处有一个 \(k\) 叉高度为 \(m\) 的堆: 若 \(m = 1\) ,则 \(p\) 本身就是一个 \(k\ ...
- Codeforces Round #165 (Div. 1) Greenhouse Effect(DP)
Greenhouse Effect time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces Round #658 (Div. 2) D. Unmerge(dp)
题目链接:https://codeforces.com/contest/1382/problem/D 题意 给出一个大小为 $2n$ 的排列,判断能否找到两个长为 $n$ 的子序列,使得二者归并排序后 ...
- Codeforces Round #652 (Div. 2) D. TediousLee(dp)
题目链接:https://codeforces.com/contest/1369/problem/D 题意 最初有一个结点,衍生规则如下: 如果结点 $u$ 没有子结点,添加 $1$ 个子结点 如果结 ...
随机推荐
- springboot mybatis 项目框架源码 shiro 集成代码生成器 ehcache缓存
1.代码生成器: [正反双向](单表.主表.明细表.树形表,快速开发利器)freemaker模版技术 ,0个代码不用写,生成完整的一个模块,带页面.建表sql脚本.处理类.service等完整模块2. ...
- candy——动态规划
There are N children standing in a line. Each child is assigned a rating value. You are giving candi ...
- CellularAutomation(细胞自己主动机)
CellularAutomation(细胞自己主动机) 细胞自己主动机(英语:Cellular automaton).又称格状自己主动机.元胞自己主动机,是一种离散模型,在可算性理论.数学及理论生物学 ...
- webform的操作完之后返回主页面的行定位
1.在repeater表格的行绑定时给行一个id(唯一id),此地方为绑定该表格的主键. watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMDA3OD ...
- HDU 5327 Olympiad (多校)
Olympiad Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Su ...
- W5500EVB TCP Server演示
之前给大家展示了p=6471" style="margin:0px; padding:0px; border:0px; font-family:inherit; font-size ...
- word2vec学习 spark版
参考资料: http://ir.dlut.edu.cn/NewsShow.aspx?ID=291 http://www.douban.com/note/298095260/ http://machin ...
- yarn笔记
常用命令: 创建项目:yarn init 安装依赖包:yarn == yarn install 添加依赖包:yarn add Yarn命令列表 命令 操作 参数 标签 yarn add 添加依赖包 包 ...
- luogu2398 SUM GCD
题目大意:求sum i(1->n) (sum j(1->n) (gcd(i,j))). 对于每对(i,j)都来一次gcd很慢,但是我们知道,一个约数i在1~n范围内是n/i个数的约数.gc ...
- STM32的低功耗设置
因为产品需求,系统功耗是一个很重要的考虑方面.好好看下STM32F103的低功耗问题,以便编写驱动. 1.STM32的电源 1.1 STM32电源框图 上面的电源中需要注意的是后备供电区域,这个部分由 ...