【codeforces 803E】Roma and Poker
【题目链接】:http://codeforces.com/contest/803/problem/E
【题意】
给你一个不完整的胜负平序列(不完整是指中间有些地方为问号,让你自己选择胜负平)
让你复原一个有关胜、负、平、的结果序列
(从左到右按时间有序)
要求在前n-1秒;
胜负场数之差任意时刻都不能超过k;
且在第n秒,胜负场数值差刚好为k;
【题解】
设f[i][j]表示前i场游戏,胜场与负场的差为j的情况能不能达到;
能达到就为true;并记录是怎么达到的(即是赢一场达到的还是输还是…)
这样进行DP
第一层枚举从0..n-1
然后第二层循环只从-k+1枚举到k-1
这样能保证在进行DP的时候选举的状态都是胜场与负场的差的绝对值小于k的;
然后最后一秒(第n秒是可以为k的)
刚好也能更新到.
【Number Of WA】
0
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1e3+10;
int n,k;
char f[1100][2*1100];
bool bo[1100][2*1100];
char s[N];
int main()
{
//freopen("F:\\rush.txt","r",stdin);
ios::sync_with_stdio(false),cin.tie(0);//scanf,puts,printf not use
cin >> n >> k;
cin >> (s+1);
bo[0][0+N] = true;
rep1(i,0,n-1)
{
rep1(j,-k+1,k-1)
if (bo[i][j+N])
{
if (s[i+1]=='W' || s[i+1]=='?')
{
bo[i+1][j+N+1] = true;
f[i+1][j+N+1] = 'W';
}
if (s[i+1]=='L' || s[i+1]=='?')
{
bo[i+1][j+N-1] = true;
f[i+1][j+N-1] = 'L';
}
if (s[i+1]=='D' || s[i+1]=='?')
{
bo[i+1][j+N] = true;
f[i+1][j+N] = 'D';
}
}
}
if (bo[n][-k+N]||bo[n][k+N])
{
string ans = "";
int now = bo[n][k+N]?N+k:N-k;
rep2(i,n,1)
{
ans = f[i][now] + ans;
if (f[i][now]=='W')
now--;
if (f[i][now]=='L')
now++;
}
cout << ans << endl;
}
else
cout << "NO" << endl;
return 0;
}
【codeforces 803E】Roma and Poker的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【19.77%】【codeforces 570D】Tree Requests
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
- 【Codeforces 429D】 Tricky Function
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...
- 【Codeforces 670C】 Cinema
[题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...
随机推荐
- HDU 5358(2015多校联合训练赛第六场1006) First One (区间合并+常数优化)
pid=5358">HDU 5358 题意: 求∑i=1n∑j=in(⌊log2S(i,j)⌋+1)∗(i+j). 思路: S(i,j) < 10^10 & ...
- 内核调试神器SystemTap — 简单介绍与使用(一)
a linux trace/probe tool. 官网:https://sourceware.org/systemtap/ 简单介绍 SystemTap是我眼下所知的最强大的内核调试工具,有些家伙甚 ...
- Online Object Tracking: A Benchmark 论文笔记
Factors that affect the performance of a tracing algorithm 1 Illumination variation 2 Occlusion 3 Ba ...
- Gym-101915J The Volcano Eruption 计算几何
题面 题意:给你一个矩阵,然后有很多的圆,这些圆可能相交着,一个或者几个就导致这个矩形被分割开了,就是从最下面的边到上面的边,连线被这些圆阻隔了,每一堆圆当做一个阻碍,问一共有几个阻碍 题解:看起来好 ...
- FZU2150 Fire Game
题目: 两个熊孩子在n*m的平地上放火玩,#表示草,两个熊孩子分别选一个#格子点火,火可以向上向下向左向右在有草的格子蔓延,点火的地方时间为0,蔓延至下一格的时间依次加一.求烧完所有的草需要的最少时间 ...
- H3BPM表单设计器公式设计参考
表单设计器公式设计参考 整体说明 Ø 公式以javascript方式解析,最终支持JS语法或计算方式: Ø 公式变量以数据项为主,以{}符号表示数据项,例如数据项A,表示为{A}:如果是子表中的数据项 ...
- java中的访问修饰符2
综上所述:protected强调的是子类,deafult强调的是本包,private强调的是本类,public强调的是开放性.
- 第4章 部署模式 Three-Tiered Distribution(三级分布)
影响因素 Tiered Distribution 中讨论的影响因素也适用于此模式.有关这些通用影响因素的讨论,请参阅"Tiered Distribution".下列影响因素仅适用于 ...
- VueJS 开发常见问题集锦
由于公司的前端开始转向 VueJS,最近开始使用这个框架进行开发,遇到一些问题记录下来,以备后用. 主要写一些 官方手册 上没有写,但是实际开发中会遇到的问题,需要一定知识基础. 涉及技术栈 CLI: ...
- 应用七:Vue之适配test环境变量(2.0版)
在我们使用vue-cli创建的项目中,默认只有开发development和生产production两种环境变量:但在实际的项目开发过程中往往都会有测试环境,下面就来说一下如何适配测试环境test的环境 ...