P1535 游荡的奶牛
P1535 游荡的奶牛
题目描述
Searching for the very best grass, the cows are travelling about the pasture which is represented as a grid with N rows and M columns (2 <= N <= 100; 2 <= M <= 100). Keen observer Farmer John has recorded Bessie's position as (R1, C1) at a certain time and then as (R2, C2) exactly T (0 < T <= 15) seconds later. He's not sure if she passed through (R2, C2) before T seconds, but he knows she is there at time T.
FJ wants a program that uses this information to calculate an integer S that is the number of ways a cow can go from (R1, C1) to (R2, C2) exactly in T seconds. Every second, a cow can travel from any position to a vertically or horizontally neighboring position in the pasture each second (no resting for the cows). Of course, the pasture has trees through which no cow can travel.
Given a map with '.'s for open pasture space and '*' for trees, calculate the number of possible ways to travel from (R1, C1) to (R2, C2) in T seconds.
奶牛们在被划分成N行M列(2 <= N <= 100; 2 <= M <= 100)的草地上游走, 试图找到整块草地中最美味的牧草。Farmer John在某个时刻看见贝茜在位置 (R1, C1),恰好T (0 < T <= 15)秒后,FJ又在位置(R2, C2)与贝茜撞了正着。 FJ并不知道在这T秒内贝茜是否曾经到过(R2, C2),他能确定的只是,现在贝茜 在那里。 设S为奶牛在T秒内从(R1, C1)走到(R2, C2)所能选择的路径总数,FJ希望有 一个程序来帮他计算这个值。每一秒内,奶牛会水平或垂直地移动1单位距离( 奶牛总是在移动,不会在某秒内停在它上一秒所在的点)。草地上的某些地方有 树,自然,奶牛不能走到树所在的位置,也不会走出草地。 现在你拿到了一张整块草地的地形图,其中'.'表示平坦的草地,'*'表示 挡路的树。你的任务是计算出,一头在T秒内从(R1, C1)移动到(R2, C2)的奶牛 可能经过的路径有哪些。
输入输出格式
输入格式:
第1 行: 3 个用空格隔开的整数:N,M,T 。 第2..N+1 行: 第i+1 行为M 个连续的字符,描述了草地第i 行各点的情况,保证字符是'.'和'*'中的一个。 第N+2 行: 4 个用空格隔开的整数:R1,C1,R2,C2 。
输出格式:
第1 行: 输出S,含义如题中所述。
输入输出样例
4 5 6
...*.
...*.
.....
.....
1 3 1 5
1
说明
样例说明:
草地被划分成4 行5 列,奶牛在6 秒内从第1 行第3 列走到了第1 行第5 列。
奶牛在6 秒内从(1,3)走到(1,5)的方法只有一种(绕过她面前的树)
居然可以用动规!!!
f[k][i][j] 表示第 k 秒到达 (i,j) 的方案
#include<cstdio>
#include<iostream> using namespace std;
const int N = ; int f[][N][N];
int mp[N][N];
int dx[] = {,,,-};
int dy[] = {,-,,};
int n,m,t,sx,sy,ex,ey;
char ch; int main()
{
scanf("%d%d%d",&n,&m,&t);
for(int i=;i<=n;++i)
for(int j=;j<=m;++j)
{
cin>>ch;
if(ch=='.') mp[i][j] = ;
}
scanf("%d%d%d%d",&sx,&sy,&ex,&ey);
f[][sx][sy] = ;
for(int k=;k<=t;++k)
for(int i=;i<=n;++i)
for(int j=;j<=m;++j)
if(mp[i][j]) for(int h=;h<;++h)
{
int xx = i+dx[h];
int yy = j+dy[h];
if(xx> && yy> && xx<=n && yy<=m && mp[xx][yy])
f[k][i][j] += f[k-][xx][yy];
}
printf("%d",f[t][ex][ey]);
return ;
}
P1535 游荡的奶牛的更多相关文章
- 洛谷 P1535 游荡的奶牛
P1535 游荡的奶牛 题目描述 Searching for the very best grass, the cows are travelling about the pasture which ...
- COGS130. [USACO Mar08] 游荡的奶牛[DP]
130. [USACO Mar08] 游荡的奶牛 ★☆ 输入文件:ctravel.in 输出文件:ctravel.out 简单对比时间限制:1 s 内存限制:128 MB 奶牛们在被划 ...
- BZOJ_1616_[Usaco2008_Mar]_Cow_Travelling_游荡的奶牛_(DP)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1616 给出一张图,有些点不能走,给出起始点和结束点,以及时间,求在该时间到达结束点的方案数. ...
- Bzoj 1616: [Usaco2008 Mar]Cow Travelling游荡的奶牛 动态规划
1616: [Usaco2008 Mar]Cow Travelling游荡的奶牛 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1006 Solved: ...
- BZOJ1616: [Usaco2008 Mar]Cow Travelling游荡的奶牛
1616: [Usaco2008 Mar]Cow Travelling游荡的奶牛 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 762 Solved: ...
- BZOJ 1616: [Usaco2008 Mar]Cow Travelling游荡的奶牛( dp )
一道水 dp ...然后我一开始用 BFS ...结果 MLE 了... dp[ i ][ j ][ k ] 由它四个方向上的 k - 1 转移. -------------------------- ...
- Luogu P1535 【游荡的奶牛】
搜索不知道为什么没有人写bfs觉得挺像是标准个bfs的 状态因为要统计次数,不能简单地跳过一个被经过的点这样的话,状态量会爆炸采用记忆化设dp[i][j][k]表示在第k分钟到达点(i,j)的方案数以 ...
- [Usaco2008 Mar]Cow Travelling游荡的奶牛[简单DP]
Description 奶牛们在被划分成N行M列(2 <= N <= 100; 2 <= M <= 100)的草地上游走,试图找到整块草地中最美味的牧草.Farmer John ...
- [bzoj 1616][Usaco2008 Mar]Cow Travelling游荡的奶牛
题目描述 奶牛们在被划分成N行M列(2 <= N <= 100; 2 <= M <= 100)的草地上游走,试图找到整块草地中最美味的牧草.Farmer John在某个时刻看见 ...
随机推荐
- matlab中boxplot字体大小设置
网上找到的:set(findobj(gca,'Type','text'),'FontSize',18) boxplot() uses the default axes labeling for the ...
- VB.NET的一个邮件发送函数
''' <summary> ''' VB.NET邮件发送程序 ''' 还没用在别的服务器,不晓得能不能行,慎用! ''' </summary> ''' <param na ...
- 处理java多线程时线程安全问题 - ThreadLocal和Synchronized
多线程在自动化测试中用的不多,也就是说我们用单线程可以完成大部分的自动化测试脚本. 主要有两个原因,首先是因为自动化测试首要考虑的是脚本的稳定性,所以一般会牺牲效率以保证脚本稳定,其次是由于局限于我们 ...
- Windows中杀死某个端口对应的进程
netstat -ano | findstr 3000 //列出进程极其占用的端口,且包含 3000 tasklist | findstr 17692 // 查看是什么程序占用的 taskkill - ...
- springBoot+mybatisPlus小demo
项目介绍:采用restful api进行接口规范 / 项目框架SpringBoot+mybatis Plus / 采用mysql进行数据存储 / 采用swaggerUI进行前后端业务分离式开发. 开发 ...
- DQL-排序查询
三:排序查询 语法: select 列名 from 表名 where 筛选条件 order by 需要排序的列名 asc/desc 特点:不写升序还是降序,默认升序 排序列表 可以是 ...
- injection for Xcode10使用方法
对于一个使用Xcode的使用者来说,麻烦的地方在于使用代码布置界面时候的调试,5s改一下代码,用10s查看修改效果,如果电脑配置稍低,时间更长,这是病,得治,哈哈.下面就来说一下injection的使 ...
- TCP/IP初识(一)
TCP/IP学习记录,如有错误请指正,谢谢!!! 什么是TCP/IP协议? TCP/IP协议族分为四层(另一个名字是Internet协议族(Internet Protocol Suite)):链路层. ...
- youku客户端
文件结构 config import os IP_PORT = ('127.0.0.1',8080) BASE_DIR = os.path.dirname(os.path.dirname(__file ...
- 史上更全的 MySQL 高性能优化实战总结!
1 前言 2 优化的哲学 3 优化思路 3.1 优化什么 3.2 优化的范围有哪些 3.3 优化维度 4 优化工具有啥? 4.1 数据库层面 4.2 数据库层面问题解决思路 4.3 系统层面 4.4 ...