803E - Roma and Poker

思路:

  赢或输或者平的序列;

  赢和平的差的绝对值不得超过k;

  结束时差的绝对值必须为k;

  当“?”时可以自己决定为什么状态;

  输出最终序列或者NO;

  dp(随便搞搞);

来,上代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; int n,k,dp[][],m; char ch[]; int main()
{
cin>>n>>k;
cin>>ch+;
m=k-;dp[][m+]=true;
for(int i=;i<n;i++)
{
if(ch[i]=='W') for(int j=;j<=m*+;j++) dp[i][j]=dp[i-][j-];
else if(ch[i]=='L') for(int j=;j<m*+;j++) dp[i][j]=dp[i-][j+];
else if(ch[i]=='D') for(int j=;j<=m*+;j++) dp[i][j]=dp[i-][j];
else for(int j=;j<=m*+;j++) dp[i][j]=(dp[i-][j-]||dp[i-][j]||dp[i-][j+]);
}
if(ch[n]=='W') dp[n][*m+]=dp[n-][*m+];
else if(ch[n]=='L') dp[n][]=dp[n-][];
else if(ch[n]=='D') ;
else dp[n][]=dp[n-][],dp[n][m*+]=dp[n-][m*+];
if(!dp[n][]&&!dp[n][m*+]) cout<<"NO";
else
{
int now;
if(dp[n][m*+]) now=m*+;
else now=;
for(int i=n;i>;i--)
{
if(ch[i]=='L') now++;
else if(ch[i]=='W') now--;
else if(ch[i]=='D') now=now;
else
{
if(dp[i-][now+]) now++,ch[i]='L';
else if(dp[i-][now]) ch[i]='D';
else if(dp[i-][now-]) now--,ch[i]='W';
}
}
cout<<ch+;
}
return ;
}

AC日记——Roma and Poker codeforces 803e的更多相关文章

  1. AC日记——Dynamic Problem Scoring codeforces 807d

    Dynamic Problem Scoring 思路: 水题: 代码: #include <cstdio> #include <cstring> #include <io ...

  2. AC日记——Sign on Fence Codeforces 484e

    E. Sign on Fence time limit per test 4 seconds memory limit per test 256 megabytes input standard in ...

  3. AC日记——Sagheer, the Hausmeister codeforces 812b

    812B - Sagheer, the Hausmeister 思路: 搜索: 代码: #include <cstdio> #include <cstring> #includ ...

  4. AC日记——Sagheer and Crossroads codeforces 812a

    812A - Sagheer and Crossroads 思路: 模拟: 代码: #include <cstdio> #include <cstring> #include ...

  5. AC日记——Is it rated? codeforces 807a

    Is it rated? 思路: 水题: 代码: #include <cstdio> #include <cstring> using namespace std; ],b[] ...

  6. Ac日记——Distances to Zero codeforces 803b

    803B - Distances to Zero 思路: 水题: 代码: #include <cstdio> #include <cstring> #include <i ...

  7. AC日记——Mice and Holes codeforces 797f

    797F - Mice and Holes 思路: XXYXX: 代码: #include <cmath> #include <cstdio> #include <cst ...

  8. AC日记——Periodic RMQ Problem codeforces 803G

    G - Periodic RMQ Problem 思路: 题目给一段序列,然后序列复制很多次: 维护序列很多次后的性质: 线段树动态开点: 来,上代码: #include <cstdio> ...

  9. AC日记——Andryusha and Socks Codeforces 780a

    A. Andryusha and Socks time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

随机推荐

  1. Django的Field(字段)

    字段 1.models.AutoField 自增列 = int(11) 如果没有的话,默认会生成一个名称为 id 的列,如果要显示的自定义一个自增列,必须将给列设置为主键 primary_key=Tr ...

  2. Android学习记录(5)—在java中学习多线程下载之断点续传②

    在上一节中我们学习了在java中学习多线程下载的基本原理和基本用法,我们并没有讲多线程的断点续传,那么这一节我们就接着上一节来讲断点续传,断点续传的重要性不言而喻,可以不用重复下载,也可以节省时间,实 ...

  3. 《Cracking the Coding Interview》——第1章:数组和字符串——题目1

    2014-03-18 01:25 题目:给定一个字符串,判断其中是否有重复字母. 解法:对于可能有n种字符的字符集,用一个长度为n的数组统计每个字符的出现次数,大于1则表示有重复. 代码: // 1. ...

  4. 《算法》C++代码 Floyd

    今天写写最短路径的Floyd算法(有翻译叫弗洛伊德,不过这奇葩翻译用来读读就好……). 这个算法的实质,广义来讲,其实是DP(动态规划).其实按说,算法应该先说说什么贪心.搜索.DP.二分之类的基本算 ...

  5. 【Pascal's Triangle】cpp

    题目: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,R ...

  6. Swift 与众不同的地方

    Swift 与众不同的地方 switch(元组) 特点 其他语言中的switch语句只能比较离散的整形数据(字符可以转换成整数) 但是swift中可以比较整数.浮点数.字符.字符串.和元组数据类型,而 ...

  7. ASP.NET Core [2]:Middleware-请求管道的构成(笔记)

    原文链接:http://www.cnblogs.com/RainingNight/p/middleware-in-asp-net-core.html 中间件处理请求主要分为三个阶段:1. 中间件的注册 ...

  8. Python全栈工程师(while、占位符)

    ParisGabriel     Python 入门基础         UnicodeASCII 用8个位表示文字 ,最高位一定是零,低七位表示数值Unicode是由16个位组成的(65535) 最 ...

  9. sshd_config_for_centos

    # $OpenBSD: sshd_config,v // :: djm Exp $ # This is the sshd server system-wide configuration file. ...

  10. 设置hostname

    由于 http://1.2.3.4 不是一个有效的 apt 源,安装肯定会失败,我们可以在 /var/log/cloud-init.log 看到失败的信息. cloud-init 默认会将 insta ...