E. Roma and Poker 
time limit per test          

2 seconds

memory limit per test    

256 megabytes

input

standard input

output

standard output

Each evening Roma plays online poker on his favourite website. The rules of poker on this website are a bit strange: there are always two players in a hand, there are no bets, and the winner takes 1 virtual bourle from the loser.

Last evening Roma started to play poker. He decided to spend no more than k virtual bourles — he will stop immediately if the number of his loses exceeds the number of his wins by k. Also Roma will leave the game if he wins enough money for the evening, i.e. if the number of wins exceeds the number of loses by k.

Next morning Roma found a piece of paper with a sequence on it representing his results. Roma doesn't remember the results exactly, and some characters in the sequence are written in a way such that it's impossible to recognize this character, so Roma can't recall whether he won k bourles or he lost.

The sequence written by Roma is a string s consisting of characters W (Roma won the corresponding hand), L (Roma lost), D (draw) and? (unknown result). Roma wants to restore any valid sequence by changing all ? characters to W, L or D. The sequence is called valid if all these conditions are met:

  • In the end the absolute difference between the number of wins and loses is equal to k;
  • There is no hand such that the absolute difference before this hand was equal to k.

Help Roma to restore any such sequence.

Input

The first line contains two numbers n (the length of Roma's sequence) and k (1 ≤ n, k ≤ 1000).

The second line contains the sequence s consisting of characters W, L, D and ?. There are exactly n characters in this sequence.

Output

If there is no valid sequence that can be obtained from s by replacing all ? characters by W, L or D, print NO.

Otherwise print this sequence. If there are multiple answers, print any of them.

Examples
input
3 2
L??
output
LDL
input
3 1
W??
output
NO
input
20 5
?LLLLLWWWWW?????????
output
WLLLLLWWWWWWWWLWLWDW

题意:
有n场比赛,给出一个k值,每场比赛的结果用W表示胜,L表示败,D表示平, ? 表示未知
?处可以自定义 胜负平
问是否有一个序列满足以下2个要求,有则输出序列,无则输出NO
设前i场胜W【i】,负L【i】
1、前n-1场中,不能有|W[i]-L[i]|>=k
2、最后一场,|W[n]-L[n]|=k
f[i][j]表示前i场W[i]-L[i]的差为j
差可能为负,整体后移n位
#include<cstdio>
#include<iostream>
using namespace std;
int n,m;
char ch[];
bool f[][];
int main()
{
scanf("%d%d",&n,&m);
scanf("%s",ch+);
f[][n+]=true;
for(int i=;i<=n;i++)
for(int j=n-i+;j<=n+i+;j++)
if(i!=n&&(j<=n-m+||j>=n+m+)) continue;
else if(ch[i]=='L'&&f[i-][j+]) f[i][j]=true;
else if(ch[i]=='W'&&f[i-][j-]) f[i][j]=true;
else if(ch[i]=='D'&&f[i-][j]) f[i][j]=true;
else if(ch[i]=='?'&&(f[i-][j-]||f[i-][j+]||f[i-][j])) f[i][j]=true;
if(!f[n][n-m+]&&!f[n][n+m+]) puts("NO");
else
{
int now;
if(f[n][n+m+]) now=n+m+;
else now=n-m+;
for(int i=n;i>;i--)
if(ch[i]=='L') now++;
else if(ch[i]=='W') now--;
else if(ch[i]=='?')
{
if(f[i-][now-]) ch[i]='W',now--;
else if(f[i-][now+]) ch[i]='L',now++;
else ch[i]='D';
}
if(now==n+) ch[]='D';
else if(now==n) ch[]='L';
else ch[]='W';
printf("%s",ch+);
}
}

Codeforces 803E - Roma and Poker的更多相关文章

  1. AC日记——Roma and Poker codeforces 803e

    803E - Roma and Poker 思路: 赢或输或者平的序列: 赢和平的差的绝对值不得超过k: 结束时差的绝对值必须为k: 当“?”时可以自己决定为什么状态: 输出最终序列或者NO: dp( ...

  2. 【codeforces 803E】Roma and Poker

    [题目链接]:http://codeforces.com/contest/803/problem/E [题意] 给你一个不完整的胜负平序列(不完整是指中间有些地方为问号,让你自己选择胜负平) 让你复原 ...

  3. Educational Codeforces Round 20 E - Roma and Poker(dp)

    传送门 题意 Roma在玩一个游戏,一共玩了n局,赢则bourle+1,输则bourle-1,Roma将会在以下情况中退出 1.他赢了k个bourle 2.他输了k个bourle 现在给出一个字符串 ...

  4. CodeForces 573A Bear and Poker

    题目链接:http://codeforces.com/problemset/problem/573/A 题目大意:此题要求一组数中的元素乘以2或者乘以3后得到的数都一样,其实就是判断这些数除去2和3这 ...

  5. codeforces B. Roma and Changing Signs 解题报告

    题目链接:http://codeforces.com/problemset/problem/262/B 题目意思:给出 n 个数和恰好一共要做的操作总数k.通过对n个数进行k次操作,每次操作可以把a[ ...

  6. Educational Codeforces Round 20

    Educational Codeforces Round 20  A. Maximal Binary Matrix 直接从上到下从左到右填,注意只剩一个要填的位置的情况 view code //#pr ...

  7. Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 1) A. Bear and Poker 分解

    A. Bear and Poker Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/573/pro ...

  8. Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2)C. Bear and Poker

                                                  C. Bear and Poker                                     ...

  9. Codeforces Round #160 (Div. 2)---A. Roma and Lucky Numbers

    Roma and Lucky Numbers time limit per test 1 second memory limit per test 256 megabytes input standa ...

随机推荐

  1. 软工 · 第十一次作业 - Alpha 事后诸葛亮(团队)

    软工 · 第十一次作业 - Alpha 事后诸葛亮(团队) 组长本次作业链接 现代软件工程 项目Postmortem 设想和目标 1.我们的软件要解决什么问题?是否定义得很清楚?是否对典型用户和典型场 ...

  2. Beta版冲刺前准备

    [团队概要] 团队项目名:小葵日记 团队名:日不落战队 队员及角色: 队员 角色 备注 安琪 前端工程师 队长 佳莹 前端工程师 智慧 后端工程师 章鹏 后端工程师 语恳 UI设计师 炜坤 前端工程师 ...

  3. Codeforces Beta Round #7 D. Palindrome Degree manacher算法+dp

    题目链接: http://codeforces.com/problemset/problem/7/D D. Palindrome Degree time limit per test1 secondm ...

  4. 在.net项目中使用Consul

    1.创建.net core web程序并运行 2.在Consul中注册该服务 Consul支持两种服务注册的方式,一种是通过Consul的服务注册HTTP API,由服务自身在启动后调用API注册自己 ...

  5. 使用rand替换random模块

    random模块使用相同的种子,在不同的进程中会出现相同的结果. rand的模块使用不同的种子,在不同的进程中不会出现相同的结果. 2个模块都是erlang自带的. 然后erlang在文档里面注明推荐 ...

  6. 服务器BMC(带外)

    服务器除了装linux,windows系统外,相应还有一个可通过网线(服务器默认带外地址--可改)连接具体厂商服务器的BMC(Baseboard Management Controller,基板管理控 ...

  7. windows系统,可以ping通IP但是不能ping通网址的解决方法

    之前慌忙之中遇到过一次,当时是客户比较着急使用就没有怎么折腾,什么数据当时都没留下反正是各种方法都尝试过了,但是就是ping IP是可以通的,但是域名就是不解析,后来有个群友也是遇见了这个问题(我当时 ...

  8. SQL入门之集合操作

    尽管可以在与数据库交互时一次只处理一行数据,但实际上关系数据库通常处理的都是数据的集合.在数学上常用的集合操作为:并(union),交(intersect),差(except).对于集合运算必须满足下 ...

  9. CPP 替代 PIL 图片处理(缩略图生成)

    python中使用PIL(Pyhton Image Library)进行图片处理,好处就是编写简单方便,但是不能很好利用机器多核的特点,于是在项目中决定使用cpp来实现图片处理. 项目中的图片处理主要 ...

  10. 简单配置AAA认证与telnet图解

    不罗嗦,直接上图