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[ ...
随机推荐
- 最短路径:HDU2006-一个人的旅行(多个起点,多个终点)
题目: 一个人的旅行 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- [GDOI2016][树链剖分+主席树]疯狂动物城
题面 Description Nick 是只在动物城以坑蒙拐骗为生的狐狸,儿时受到偏见的伤害,放弃了自己的理想.他被兔子 Judy 设下圈套,被迫与她合作查案,而卷入意想不到的阴谋,历尽艰险后成为搭档 ...
- HDU 2177 取(2堆)石子游戏
取(2堆)石子游戏 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- Linux磁盘与文件管理系统
基本上Linux的正统文件系统为Ext2,该文件系统内的信息主要有: superblock:记录此filesystem的整体信息,包括inode/block的总量,使用量,剩余量,以及文件系统的格式与 ...
- laravel5.2总结--邮件
laravel自带SwiftMailer库,集成了多种邮件API,支持多种邮件驱动方式,包括smtp.Mailgun.Maildrill.Amazon SES.mail和sendmail,Mailgu ...
- OpenStack之虚机冷迁移代码简析
OpenStack之虚机冷迁移代码简析 前不久我们看了openstack的热迁移代码,并进行了简单的分析.真的,很简单的分析.现在天气凉了,为了应时令,再简析下虚机冷迁移的代码. 还是老样子,前端的H ...
- 【Search In Rotated Sorted Array】cpp
题目: Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 ...
- leetcode 【 Search Insert Position 】python 实现
题目: Given a sorted array and a target value, return the index if the target is found. If not, return ...
- Python+Selenium练习篇之21-如何截图并保存
本文介绍如何利用Selenium的方法进行截图,在测试过程中,是有必要截图,特别是遇到错误的时候进行截图.在selenium for python中主要有三个截图方法,我们挑选其中最常用的一种. ge ...
- Mac OS X 上的Apache配置
Mac系统自带apache服务器 查看apache版本 sudo apachectl -v 启动apache sudo apachectl start 重启apache sudo apachectl ...