传送门

题意

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)的更多相关文章

  1. Educational Codeforces Round 16 E. Generate a String (DP)

    Generate a String 题目链接: http://codeforces.com/contest/710/problem/E Description zscoder wants to gen ...

  2. Educational Codeforces Round 22 B. The Golden Age(暴力)

    题目链接:http://codeforces.com/contest/813/problem/B 题意:就是有一个数叫做不幸运数,满足题目的 n = x^a + y^b,现在给你一个区间[l,r],让 ...

  3. 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 ...

  4. Educational Codeforces Round 54 [Rated for Div. 2] (CF1076)

    第一次在宿舍打CF 把同宿舍的妹子吵得不行... 特此抱歉QAQ A 题意:给定一个字符串, 最多删掉一个字符,使得剩余字符串字典序最小 n<=2e5 当然"最多"是假的 删 ...

  5. Educational Codeforces Round 32:E. Maximum Subsequence(Meet-in-the-middle)

    题目链接:E. Maximum Subsequence 用了一个Meet-in-the-middle的技巧,还是第一次用到这个技巧,其实这个技巧和二分很像,主要是在dfs中,如果数量减小一半可以节约很 ...

  6. Codeforces Round #471 (Div. 2) F. Heaps(dp)

    题意 给定一棵以 \(1\) 号点为根的树.若满足以下条件,则认为节点 \(p\) 处有一个 \(k\) 叉高度为 \(m\) 的堆: 若 \(m = 1\) ,则 \(p\) 本身就是一个 \(k\ ...

  7. 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 ...

  8. Codeforces Round #658 (Div. 2) D. Unmerge(dp)

    题目链接:https://codeforces.com/contest/1382/problem/D 题意 给出一个大小为 $2n$ 的排列,判断能否找到两个长为 $n$ 的子序列,使得二者归并排序后 ...

  9. Codeforces Round #652 (Div. 2) D. TediousLee(dp)

    题目链接:https://codeforces.com/contest/1369/problem/D 题意 最初有一个结点,衍生规则如下: 如果结点 $u$ 没有子结点,添加 $1$ 个子结点 如果结 ...

随机推荐

  1. JQUERY多选框,单选框,检查选中的值

    var str=""; $(":checkbox:checked").each(function(){ if($(this).attr("checke ...

  2. 面向对象 委托变量和this的使用

    委托方法: this的使用:

  3. CPU Stepping

    http://baike.baidu.com/view/16839.htm?fr=ala0_1_1 步进 编辑   步进(Stepping)是CPU的一个重要参数,也叫分级鉴别产品数据转换规范,“步进 ...

  4. mysql有哪几种索引

    从数据结构角度 1.  B+树索引(O(log(n))) 2.  hash索引 3.  FULLTEXT索引 4.  R-Tree索引 从物理存储角度 1. 聚集索引 2.  非聚集索引 从逻辑角度 ...

  5. OOP思想又一随笔

    现有类再有对象, 类:对现实世界事物的抽象表示,包括事物的状态信息(成员变量)和行为信息(成员方法).我们要让我们的计算机程序设计更有意思,也更有逻辑性,则我们的程序中对事物的描叙就必须符合真实情况, ...

  6. HDU 1032.The 3n + 1 problem【注意细节】【预计数据不强】【8月21】

    The 3n + 1 problem Problem Description Problems in Computer Science are often classified as belongin ...

  7. Lazy freeing of keys 对数据的额异步 同步操作 Redis 4.0 微信小程序

    https://github.com/antirez/redis/blob/4.0-rc1/00-RELEASENOTES 数据缓存 · 小程序 https://developers.weixin.q ...

  8. Axure Base 10 动态面板滑动效果

    示例原型:http://pan.baidu.com/s/1mgjYahi 实现目标: 1.  点击登录滑出登录面板 2.  点击确定滑出动态面板 最终效果如下: 这种效果可以通过两种方法实现: 首先准 ...

  9. Linux系统(Centos)下安装Java环境配置步骤详述

    1.首先要去下载好JDK,Java SE 8的官方网址是http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2 ...

  10. Servlet session的理解

    servlet参见http://blog.csdn.net/bryanliu1982/article/details/5214899 session参见http://lavasoft.blog.51c ...