Codeforces 586D Phillip and Trains(DP)
题目链接 Phillip and Trains
考虑相对位移。
每一轮人向右移动一格,再在竖直方向上移动0~1格,列车再向左移动两格。
这个过程相当于每一轮人向右移动一格,再在竖直方向上移动0~1格,然后人再向右移动两格。
然后就可以进行状态转移了。
f[i][j]表示能否走到i行j列的位置。最后在终点处查找是否存在f[i][ed]为1即可。
#include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i(a); i <= (b); ++i) int f[][];
char st[][];
int T, n, k, ed;
bool flag; int main(){ scanf("%d", &T);
for (; T--;){
scanf("%d%d", &n, &k);
memset(f, , sizeof f);
rep(i, , ) scanf("%s", st[i] + );
rep(i, , ) rep(j, n + , n + ) st[i][j] = '.';
rep(i, , ) st[i][n + ] = '\0';
for (ed = ; ed < n + ; ) ed += ;
rep(i, , ) if (st[i][] == 's') f[i][] = , st[i][] = '.'; for (int j = ; j <= ed; j += ){
rep(i, , ){
if (st[i][j] != '.') continue;
if (st[i][j - ] != '.') continue;
if (st[i][j - ] != '.') continue;
rep(k, i - , i + ){
if (k < || k > ) continue;
if (st[k][j - ] != '.') continue;
if (st[k][j - ] != '.') continue;
f[i][j] |= f[k][j - ];
}
}
} flag = false;
rep(i, , ) rep(j, n, ed)
if (f[i][j]){ flag = true; break;} puts(flag ? "YES" : "NO"); } return ; }
Codeforces 586D Phillip and Trains(DP)的更多相关文章
- Codeforces 586D. Phillip and Trains 搜索
D. Phillip and Trains time limit per test: 1 second memory limit per test :256 megabytes input: stan ...
- CodeForces - 710E Generate a String (dp)
题意:构造一个由a组成的串,如果插入或删除一个a,花费时间x,如果使当前串长度加倍,花费时间y,问要构造一个长度为n的串,最少花费多长时间. 分析:dp[i]---构造长度为i的串需要花费的最短时间. ...
- Educational Codeforces Round 51 D. Bicolorings(dp)
https://codeforces.com/contest/1051/problem/D 题意 一个2*n的矩阵,你可以用黑白格子去填充他,求联通块数目等于k的方案数,答案%998244353. 思 ...
- Codeforces 536D - Tavas in Kansas(dp)
Codeforces 题目传送门 & 洛谷题目传送门 其实这题本该 2019 年 12 月就 AC 的(详情请见 ycx 发此题题解的时间),然鹅鸽到了现在-- 首先以 \(s,t\) 分别为 ...
- CodeForces - 586D Phillip and Trains 搜索。vis 剪枝。
http://codeforces.com/problemset/problem/586/D 题意:有一个3*n(n<100)的隧道.一个人在最左边,要走到最右边,每次他先向右移动一格,再上下移 ...
- Codeforces 295D - Greg and Caves(dp)
题意: 给出一个 \(n \times m\) 的矩阵,需对其进行黑白染色,使得以下条件成立: 存在区间 \([l,r]\)(\(1\leq l\leq r\leq n\)),使得第 \(l,l+1, ...
- Codeforces 467C George and Job(DP)
题目 Source http://codeforces.com/contest/467/problem/C Description The new ITone 6 has been released ...
- 【 Gym - 101138K 】 The World of Trains (DP)
BUPT2017 wintertraining(15) #4E Gym - 101138K 题意 N节车厢的火车,每节车厢容量是1~K,那么有\(K^N\)种火车. 求选择D个连续的且容量相同的车厢的 ...
- Codeforces A ACM (ACronym Maker) (dp)
http://codeforces.com/gym/100650 概要:给出一个缩写,和一些单词,从单词中按顺序选一些字母作为缩写,问方案数. 限制:某些单词要忽略,每个单词至少要选一个字母. dp[ ...
随机推荐
- HDU:3336-Count the string(next数组理解)
Count the string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Pr ...
- 笔记-python-standard library-8.10 copy
笔记-python-standard library-8.10 copy 1. copy source code:Lib/copy.py python中的赋值语句不复制对象,它创建了对象和目 ...
- TCP/IP网络编程之多播与广播
多播 多播方式的数据传输是基于UDP完成的,因此,与UDP服务端/客户端的实现非常接近.区别在于,UDP数据传输以单一目标进行,而多播数据同时传递到加入(注册)特定组的大量主机.换言之,采用多播方式时 ...
- luogu2870 [USACO07DEC]最佳牛线,黄金Best Cow Line, Gold
ref #include <iostream> #include <cstring> #include <cstdio> using namespace std; ...
- jmeter将上一个请求的结果作为下一个请求的参数——使用正则提取器
转自:http://www.cnblogs.com/0201zcr/p/5089620.html 在压力测试的时候,经常要将几个流程串联起来才能将程序测试通过.如:我现在用户首先要登录,获得我登录的凭 ...
- 在IE浏览器下,PDF将弹出窗口遮挡了
写了个embed标签里面放这个pdf 然后点击其他地方的弹框pdf把他遮盖住了 如下: 先是改z-index,没卵用. 百度了好久,终于找到了个有用的 https://blog.csdn.net/it ...
- uploadify 报http 302错误
uploadify 报http 302错误 原因是系统采用Forms认证,服务端加入匿名认证即可 具体配置如下: <location path="Base/Base/Upload&qu ...
- shell执行mysql的脚本(包括mysql执行shell脚本)
在Shell中执行mysql的脚本,这里介绍比较容易使用的一种方法 首先写好sql的脚本,后缀为.sql,比如 sql_file.sql:内容如下 #这是SQL的脚本create table if n ...
- selenium webdriver——元素操作
#Author:xiaoxiao from selenium import webdriver import time def abcd(): driver = webdriver.Firefox() ...
- java中的读/写锁
读写锁接口:ReadWriteLock,它的具体实现类为:ReentrantReadWriteLock 使用场景: 对于一个资源,读读能共存,读写不能共存,写写不能共存. 锁降级:从写锁变成读锁: 锁 ...