dp

dp[i][j]表示到了i赢和输的差为j

如果这位是?向dp[i-1][j-1],dp[i-1][j],dp[i-1][j+1]转移,如果是W向dp[i-1][j-1]转移,如果是L向dp[i-1][j+1]转移,如果是D向dp[i-1][j]转移

#include<bits/stdc++.h>
using namespace std;
const int N = ;
int n, k;
char s[N], ans[N][N * ];
int dp[N][N * ], pre[N][N * ];
int main()
{
scanf("%d%d", &n, &k);
scanf("%s", s + );
dp[][] = ;
for(int i = ; i <= n; ++i)
for(int j = -k + ; j <= k + ; ++j)
{
ans[i][j] = s[i];
if(s[i] == '?')
{
for(int l = -; l <= ; ++l) if(abs(j + l - ) < k && dp[i - ][j + l])
{
dp[i][j] = dp[i - ][j + l];
if(l == -) ans[i][j] = 'W';
else if(l == ) ans[i][j] = 'D';
else if(l == ) ans[i][j] = 'L';
pre[i][j] = j + l;
}
}
else if(s[i] == 'W')
{
if(abs(j - ) < k && dp[i - ][j - ])
{
dp[i][j] = ;
pre[i][j] = j - ;
}
}
else if(s[i] == 'L')
{
if(abs(j - ) < k && dp[i - ][j + ])
{
dp[i][j] = ;
pre[i][j] = j + ;
}
}
else if(s[i] == 'D')
{
if(abs(j - ) < k && dp[i - ][j])
{
pre[i][j] = j;
dp[i][j] = ;
}
}
}
if(!dp[n][k + ] && !dp[n][-k + ])
{
puts("NO");
return ;
}
vector<char> v;
int now = dp[n][k + ] ? k + : -k + ;
for(int i = now, j = n; i && j; i = pre[j][i], --j)
v.push_back(ans[j][i]);
reverse(v.begin(), v.end());
for(int i = ; i < v.size(); ++i) printf("%c", v[i]);
return ;
}

803E的更多相关文章

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

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

  2. Codeforces 803E - Roma and Poker

    http://codeforces.com/problemset/problem/803/E E. Roma and Poker  time limit per test           2 se ...

  3. 【codeforces 803E】Roma and Poker

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

  4. [反汇编练习] 160个CrackMe之018

    [反汇编练习] 160个CrackMe之018. 本系列文章的目的是从一个没有任何经验的新手的角度(其实就是我自己),一步步尝试将160个CrackMe全部破解,如果可以,通过任何方式写出一个类似于注 ...

  5. 电脑一直报PCIE BUS错误的原因

    报错 新装Linux 系统后,每隔数分钟则报以下错误: AER:Corrected error received: 0000:00:1c:4 pcie bus error: severity=Corr ...

  6. yaffs2在am335x上实施

    一.yaffs2文件烧写(通过网口) uboot下输入如下命令: setenv ipaddr 192.168.2.110;setenv serverip 192.168.2.222;saveenv n ...

  7. 菜鸟 学注册机编写之 “MD5”

    测试环境  系统: xp sp3 调试器 :od 1.10 sc_office_2003_pro 高手不要见笑,仅供小菜玩乐,有不对或不足的地方还请多多指教,不胜感激! 一:定位关键CALL 1. 因 ...

随机推荐

  1. eclipse版本和jdk的版本兼容问题

    eclipse也是有版本的,当版本过低时,无法兼容高版本的jdk 项目中用的是jdk1.8,但是低版本的eclipse只能选到jdk1.7,导致java文件在编译的过程中,不识别1.8版本jdk的语法 ...

  2. jq购物车结算功能

    css *{font-style: normal} .gw{margin: 8px;} .gw::after{display: block;clear: both;content: '';margin ...

  3. 本地读取服务器Xml文件及本地读本地的xml

    updateUrl="ServerUrl"(服务器路径) WebClient wc = new WebClient(); Stream stream = wc.OpenRead(u ...

  4. Windows下Unity安装

    安装教程: https://www.paws3d.com/lesson/us-0101/ 问题1: 安装并完成注册后,在网页上能登录,但打开Unity时不能启动成功,一直停留在如下界面 解决方案:断网 ...

  5. php 漏洞分析

    addslashes() 函数返回在预定义字符之前添加反斜杠的字符串.

  6. bupt summer training for 16 #4 ——数论

    https://vjudge.net/contest/173277#overview A.平方差公式后变为 n = (x + y)(x - y) 令 t = x - y ,变成 n = (t + 2x ...

  7. Divisible Group Sums

    Divisible Group Sums Given a list of N numbers you will be allowed to choose any M of them. So you c ...

  8. python实现字符串之间的映射

    类似于凯撒密码一样的加密 # *-* coding=utf-8 *-* import string intab = string.lowercase outtab = 'qwertyuiopasdfg ...

  9. [bzoj1468][poj1741]Tree[点分治]

    可以说是点分治第一题,之前那道的点分治只是模模糊糊,做完这道题感觉清楚了很多,点分治可以理解为每次树的重心(这样会把数分为若干棵子树,子树大小为log级别),然后统计包含重心的整个子树的值减去各个子树 ...

  10. Linux imooc learning

    https://www.imooc.com/video/3529 Windows Vs Linux Linux: (other linux overall   https://onedrive.liv ...