BZOJ Usaco 1616 Cow Travelling
阿新 • • 發佈:2017-09-08
scan tdi pan for log spa == cstring str
一開始還以為是BFS,但是發現臥槽寫挫了。
後來想了想如果去掉參數T,那麽就是一個棋盤形DP了。
那題目不過多了一個T,只需要DP加一維就可以了啊。
=W= 還是我太菜了
1 #include <cstdio> 2 #include <algorithm> 3 #include <cstring> 4 5 using namespace std; 6 7 int n,m,t; 8 int Map[122][122]; 9 int Ex,Ey,Sx,Sy; 10 int dp[122][122][20]; 1112 int main(){ 13 scanf("%d%d%d",&n,&m,&t); 14 for(int i=1;i<=n;i++){ 15 char s[105]; 16 scanf("%s",s+1); 17 for(int j=1;j<=m;j++){ 18 if(s[j]==‘*‘) Map[i][j]=1; 19 } 20 } 21 scanf("%d%d%d%d",&Sx,&Sy,&Ex,&Ey);22 dp[Sx][Sy][0]=1; 23 for(int T=1;T<=t;T++){ 24 for(int i=1;i<=n;i++){ 25 for(int j=1;j<=m;j++){ 26 if(!Map[i][j])dp[i][j][T]+=(dp[i-1][j][T-1]+dp[i+1][j][T-1]+dp[i][j-1][T-1]+dp[i][j+1][T-1]); 27 } 28 } 29 } 3031 printf("%d\n",dp[Ex][Ey][t]); 32 return 0; 33 34 }
BZOJ Usaco 1616 Cow Travelling