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. Beta冲刺贡献分数分配结果

    小组名称:Hello World! 项目名称:空天猎 组长:陈建宇 成员:刘成志.刘耀泽.刘淑霞.黄泽宇.方铭.贾男男 第三周贡献分分配结果 基础分 会议分 个人贡献分 最终分数 黄泽宇 9 0.5 ...

  2. Thunder团队第七周 - Scrum会议5

    Scrum会议5 小组名称:Thunder 项目名称:i阅app Scrum Master:邹双黛 工作照片: 宋雨沉迷于照相无法自拔,所以不在相片中. 参会成员: 王航:http://www.cnb ...

  3. C++对象模型 多重继承与虚函数表

    一 多重继承 1) 代码: Code#include <iostream>using namespace std; class B1{public:    int x;    virtua ...

  4. PAT L1-032 Left-pad

    https://pintia.cn/problem-sets/994805046380707840/problems/994805100684361728 根据新浪微博上的消息,有一位开发者不满NPM ...

  5. Ribbon源码解析

    SpringCloud中的Ribbon开源项目,提供了客户端的负载均衡算法.这篇文章,我们来介绍下他是如何实现的.为了方便理解,我们以客户端调用的流程来介绍,其中会穿插介绍相关源代码. 简单回顾下Ri ...

  6. 修改mac的hosts文件

    第一步:请先打开 Mac 系统中的 Finder 应用,接下来请按快捷键组合 Shift+Command+G 三个组合按键,并输入 Hosts 文件的所在路径:/etc/hosts , 随后即可在 F ...

  7. python/django将mysql查询结果转换为字典组

    使用python查询mysql数据库的时候,默认查询结果没有返回表字段名称,不方便使用.为了方便使用一般会选择将查询结果加上字段名称以字典组的方式返回查询结果. 实现如下: def dict_fetc ...

  8. PHP中访问控制修饰符

    访问控制修饰符 形式: class  类名{ 访问控制修饰符  属性或方法定义: } 有3个访问修饰符: public公共的:在所有位置都可访问(使用). protected受保护的:只能再该类内部和 ...

  9. oracle锁与死锁概念,阻塞产生的原因以及解决方案

    锁是一种机制,一直存在:死锁是一种错误,尽量避免.​ 首先,要理解锁和死锁的概念:​ 1.锁: 定义:简单的说,锁是数据库为了保证数据的一致性而存在的一种机制,其他数据库一样有,只不过实现机制上可能大 ...

  10. BZOJ3620 似乎在梦中见过的样子(kmp)

    不是很懂为什么数据范围要开的这么诡异,想到正解都不敢写.用类似NOI2014动物园的方法,对每个后缀求出类似next的数组即可. #include<iostream> #include&l ...