题目链接:
http://www.lydsy.com/JudgeOnline/problem.php?id=1616
题解:
也是一道dp题,感觉dp题好多
dp[i][j][t]表示在第t秒时到达(i,j)点的方法数,然后很简单的递推即可。
代码:
#include<iostream>
#include<algorithm>
#include<stdio.h>
using namespace std;
int n,m,T,dp[105][105][20],map[105][105],stx,sty,edx,edy;
int d[2][4]={{0,0,-1,1},{1,-1,0,0}};
char s[105];
int main()
{
scanf("%d%d%d",&n,&m,&T);
for (int i=1;i<=n;i++)
{
scanf("%s",s);
for (int j=1;j<=m;j++)
if (s[j-1]=='.')
map[i][j]=1;
else
map[i][j]=0;
}
scanf("%d%d%d%d",&stx,&sty,&edx,&edy);
dp[stx][sty][0]=1;
for (int t=1;t<=T;t++)
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
{
if (!map[i][j]) continue;
for (int k=0;k<4;k++)
dp[i][j][t]+=dp[i+d[0][k]][j+d[1][k]][t-1];
}
printf("%d\n",dp[edx][edy][T]);
}