Describe
http://www.lydsy.com/JudgeOnline/problem.php?id=1616
Give a picture, some points can not walk, give the starting point and the end point, as well as the time, for the time to reach the end of the scheme number.
Analysis
Direct DP can be.
\ (f[i][j][k]\) represents the number of scenarios that go to \ ((j,k) \) at \ (i\) time.
In \ (i\) time from point \ ((b) \) to \ ((c,d) \):
\ (f[i][c][d]+=f[i-1][a][b]\).
1#include <bits/stdc++.h>2 using namespacestd;3 4 Const intmaxn= -+5;5 intn,m,t,r1,c1,r2,c2;6 intgo[][2]={-1,0,0,-1,1,0,0,1};7 intf[ -][MAXN][MAXN];8 BOOLMAP[MAXN][MAXN];9 CharC;TenInlineintReadint&X) {x=0;intk=1;CharC for(C=getchar ();c<'0'|| C>'9'; C=getchar ())if(c=='-') k=-1; for(; c>='0'&&c<='9'; C=getchar ()) x=x*Ten+c-'0';returnx*=K;} OneInlineCharReadChar&C) { for(C=getchar (); c!='.'&&c!='*'; C=getchar ());returnC;} A intMain () { - Read ( n); Read (m); Read (t); - for(intI=1; i<=n;i++) for(intj=1; j<=m;j++) Map[i][j]=read (c) = ='.'?true:false; the Read (R1); Read (C1); Read ( R2); read (C2); -f[0][r1][c1]=1; - for(intI=1; i<=t;i++) for(intj=1; j<=n;j++) for(intk=1; k<=m;k++)if(Map[j][k]) for(intq=0;q<4; q++){ - intdx=j+go[q][0],dy=k+go[q][1]; + if(dx<=0|| dx>n| | dy<=0|| dy>m| |! f[i-1][dx][dy])Continue; -f[i][j][k]+=f[i-1][dx][dy]; + } Aprintf"%d\n", F[T][R2][C2]); at return 0; -}
View Code
1616: [Usaco2008 mar]cow travelling wandering cows time limit:5 Sec Memory limit:64 MB
submit:1060 solved:584
[Submit] [Status] [Discuss] Description
Cows are divided into N rows M-column (2 <= n <=, 2 <= m <= 100) on the upper reaches of the grassland, trying to find the most delicious pasture in the whole meadow. Farmer John at some point saw Betsy in position (R1, C1), exactly T (0 < T <= 15) Seconds later, FJ again in position (R2, C2) and Bessie banged up. FJ did not know whether Nebesi had ever been to (R2, C2) in this T-second, and he was able to ascertain just now that Bessie was there. Set S for cows in t seconds from (R1, C1) go to (R2, C2) can choose the total number of paths, FJ want to have a program to help him calculate this value. Every second, the cow moves horizontally or vertically 1 units of distance (the cow is always moving and does not stop at the point where it was a second in a second). Some places on the lawn have trees, nature, cows can not walk to the location of the tree, will not go out of the grass. Now you've got a topographic map of the whole meadow, where '. ' Represents a flat meadow, ' * ' means a tree in the way. Your task is to figure out what path a cow may have traveled from (R1, C1) to (R2, C2) within t seconds.
Input
* Line 1th: 3 integers separated by a space: n,m,t
* 2nd. N+1 Line: Section i+1 behavior m consecutive characters, describes the field of the first row of the case, the guaranteed character is '. ' And one of the * n+2:4 integers separated by a space: R1,C1,R2, and C2
Output
* Line 1th: output S, meaning title described in
Sample Input4 5 6
...*.
...*.
.....
.....
1 3 1 5
Input Description:
The lawn is divided into 4 rows and 5 columns, and the cows walk from row 3rd in line 1th to the 1th row 5th column in 6 seconds.
Sample Output1
There is only one way for a cow to walk from (1,3) to (1,5) within 6 seconds (bypassing the tree in front of her).
Hintsource
Silver
Bzoj_1616_[usaco2008_mar]_cow_travelling_ Wandering Cows _ (DP)