【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 ...
随机推荐
- 3D语音天气球(源代码分享)——通过天气服务动态创建3D球
转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990),谢谢支持! 开篇废话: 这个项目准备分四部分介绍: 一:创建可旋转的"3D球":3 ...
- cocos2dx 3.1从零学习(二)——菜单、场景切换、场景传值
回想一下上一篇的内容,我们已经学会了创建一个新的场景scene,加入sprite和label到层中.掌握了定时事件schedule. 我们能够顺利的写出打飞机的主场景框架. 上一篇的内容我练习了七个新 ...
- hdu1209(Clock)
pid=1209">点击打开hdu1209 Problem Description There is an analog clock with two hands: an hour h ...
- Python3.6 import源文件与编译文件的关系
小结: 在Python3.6中 源文件存在时,import会比较源文件与__pycache__里相应文件的时间戳,来决定是否重新生成缓存编译文件 源文件不存在时,import会导入相应的.pyc文件 ...
- Mysql数据类型(二)
字符类型 #官网:https://dev.mysql.com/doc/refman/5.7/en/char.html #注意:char和varchar括号内的参数指的都是字符的长度 #char类型:定 ...
- D - Knight Tournament(set)
Problem description Hooray! Berl II, the king of Berland is making a knight tournament. The king has ...
- CSS3伪元素、伪类选择器
伪元素选择器: ::first-letter:为某个元素中的文字的首字母或第一个字使用样式. ::first-line:为某个元素的第一行文字使用样式. ::before:在某个元素之前插入一些内容. ...
- hdu2236 无题II 最大匹配 + 二分搜索
中文题目,题意大家都明白. 看到“不同的行和列”就觉得要用二分匹配来做.要求最大值与最小值的差值最小,是通过枚举边的下限和上限来完成. 枚举过程是这样的,在输入的过程可以记录下边权的最大值MAX和最小 ...
- 四.Windows I/O模型之重叠IO(overlapped)模型
1.适用于除Windows CE之外的各种Windows平台.在使用这个模型之前应该确保该系统安装了Winsock2.重叠模型的基本设计原理是使用一个重叠的数据结构,一次投递一个或多个Winsock ...
- 深度学习:又一次推动AI梦想(Marr理论、语义鸿沟、视觉神经网络、神经形态学)
几乎每一次神经网络的再流行,都会出现:推进人工智能的梦想之说. 前言: Marr视觉分层理论 Marr视觉分层理论(百度百科):理论框架主要由视觉所建立.保持.并予以解释的三级表象结构组成,这就是: ...