bzoj1616 [Usaco2008 Mar]Cow Travelling游荡的奶牛

http://www.elijahqi.win/2017/12/30/bzoj1616-usaco2008-marcow-travelling%e6%b8%b8%e8%8d%a1%e7%9a%84%e5%a5%b6%e7%89%9b/
题目描述

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,含义如题中所述。
输入输出样例

输入样例#1: 复制

4 5 6
…*.
…*.
…..
…..
1 3 1 5

输出样例#1: 复制

1

说明

样例说明:

草地被划分成4 行5 列,奶牛在6 秒内从第1 行第3 列走到了第1 行第5 列。

奶牛在6 秒内从(1,3)走到(1,5)的方法只有一种(绕过她面前的树)

做过tjoi2017可乐之后这题就还可以了 以时间划分状态 然后 f[i][j][t]表示 我当前第ts到达 i,j这个节点的方案数是多少 直接n*n*t暴力转移即可


#include<cstdio>
int dx[]={0,1,-1,0},dy[]={1,0,0,-1},n,m,T,f[110][110][20],r1,c1,r2,c2;
char s[110][110];
int main(){
    freopen("1535.in","r",stdin);
    scanf("%d%d%d",&n,&m,&T);
    for (int i=1;i<=n;++i) scanf("%s",s[i]+1);
    scanf("%d%d%d%d",&r1,&c1,&r2,&c2);f[r1][c1][0]=1;
    for (int t=0;t<T;++t){
        for (int i=1;i<=n;++i){
            for (int j=1;j<=m;++j){
                if (s[i][j]=='*') continue;
                for (int k=0;k<4;++k){
                    int x1=i+dx[k],y1=j+dy[k];
                    if (x1<1||x1>n||y1<1||y1>m||s[x1][y1]=='*') continue;
                    f[x1][y1][t+1]+=f[i][j][t];
                }
            }
        }
    }printf("%d\n",f[r2][c2][T]);
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值