Codeforces Round #325 (Div. 2) Phillip and Trains dp
原题连接:http://codeforces.com/contest/586/problem/D
题意:
就大家都玩过地铁奔跑这个游戏(我没玩过),然后给你个当前的地铁的状况,让你判断人是否能够出去。
题解:
就首先预处理一下每个点在哪些时刻会被车子占领,然后从右向左dp一下就好
代码:
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#define MAX_N 123
using namespace std;
int n,k; string ma[]; bool d[][MAX_N][MAX_N];
int T;
bool dp[][MAX_N]; void print(){
for(int i=;i<;i++,cout<<endl)
for(int j=;j<n;j++)cout<<dp[i][j]<<" ";
cout<<"----"<<endl;
} int main(){
cin.sync_with_stdio(false);
cin>>T;
while(T--){
cin>>n>>k;
memset(dp,,sizeof(dp));
memset(d,,sizeof(d));
for(int i=;i<;i++)cin>>ma[i];
for(int i=;i<;i++)
for(int j=;j<n;j++)
if(ma[i][j]<='Z'&&ma[i][j]>='A')
for(int k=j,t=;k>=;k-=,t++)
d[i][k][t]=;
for(int i=;i<;i++)
dp[i][]=('s'==ma[i][]);
for(int j=;j<n-;j++){
for(int i=;i<;i++){
if(dp[i][j]){
if(d[i][j+][j])continue;
for(int k=;k<;k++)
if(d[k][j+][j]==&&d[k][j+][j+]==&&abs(k-i)<=)
dp[k][j+]=;
}
}
//print();
}
bool ans=;
for(int i=;i<;i++)ans|=dp[i][n-];
if(ans)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return ;
}
Codeforces Round #325 (Div. 2) Phillip and Trains dp的更多相关文章
- Codeforces Round #325 (Div. 2) D. Phillip and Trains BFS
D. Phillip and Trains Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586/ ...
- Codeforces Round #325 (Div. 2) D bfs
D. Phillip and Trains time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces Round #325 (Div. 2)
水 A - Alena's Schedule /************************************************ * Author :Running_Time * Cr ...
- Codeforces Round #174 (Div. 1) B. Cow Program(dp + 记忆化)
题目链接:http://codeforces.com/contest/283/problem/B 思路: dp[now][flag]表示现在在位置now,flag表示是接下来要做的步骤,然后根据题意记 ...
- Codeforces Round #325 (Div. 2) F. Lizard Era: Beginning meet in the mid
F. Lizard Era: Beginning Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...
- Codeforces Round #325 (Div. 2) C. Gennady the Dentist 暴力
C. Gennady the Dentist Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586 ...
- Codeforces Round #325 (Div. 2) A. Alena's Schedule 水题
A. Alena's Schedule Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586/pr ...
- Codeforces Round #325 (Div. 2) B. Laurenty and Shop 前缀和
B. Laurenty and Shop Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586/p ...
- Codeforces Round #325 (Div. 2) Laurenty and Shop 模拟
原题链接:http://codeforces.com/contest/586/problem/B 题意: 大概就是给你一个两行的路,让你寻找一个来回的最短路,并且不能走重复的路. 题解: 就枚举上下选 ...
随机推荐
- C 语言 进阶
清单狂魔,只挖坑不填坑.. 前言 最近经常被询问 C 语言 相关的问题,突然便也觉得需要思考一下 C 语言的进阶了. 我用 C 语言写过的最大的一个项目,也只是那个贪吃蛇,后来就断断续续地用 Pyth ...
- PHP基础壹
<?php //<!--//注释方式-->//<!--//echo 后面跟字符串:-->//<!--print("123");-->//& ...
- 利用nat.123实现SVN外网访问
背景: 在高效平台的合作中,我们用到了很多团队合作开发的工具,比如SVN.禅道.Confluence等等.有了这些工具,我们可以很好的进行团队合作交流.但同样有所限制,这些工具都是发布在局域网中,只能 ...
- 【DNS】DNS的几个基本概念
一. 根域 就是所谓的“.”,其实我们的网址www.baidu.com在配置当中应该是www.baidu.com.(最后有一点),一般我们在浏览器里输入时会省略后面的点,而这也已经成为了习惯. 根域服 ...
- hdu 3986 Harry Potter and the Final Battle (最短路径)
Harry Potter and the Final Battle Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65536/6553 ...
- P4285 [SHOI2008]汉诺塔
题目描述 汉诺塔由三根柱子(分别用A.B.C表示)和n个大小互不相同的空心盘子组成.一开始n个盘子都摞在柱子A上,大的在下面,小的在上面,形成了一个塔状的锥形体. 对汉诺塔的一次合法的操作是指:从一根 ...
- [Codeforces 1027 F] Session in BSU [并查集维护二分图匹配问题]
题面 传送门 思路 真是一道神奇的题目呢 题目本身可以转化为二分图匹配问题,要求右半部分选择的点的最大编号最小的一组完美匹配 注意到这里左边半部分有一个性质:每个点恰好连出两条边到右半部分 那么我们可 ...
- Codeforces Round #428 (Div. 2) B
B. Game of the Rows(贪心) 题意: 有k种颜色,每种有\(a_i\)个,将这k种颜色放在一个\(n * 8格子里\) 放置规则不能出现两个不同颜色在相邻的格子里,相邻的定义为在同一 ...
- css实现0.5像素
.border{ position: relative; } .border:before{ content: ''; position: absolute; width: 200%; height: ...
- hibernate中类状态转换