版权声明:转载注明下出处就行了。 https://blog.csdn.net/LJD201724114126/article/details/84711186
题目链接:https://ac.nowcoder.com/acm/contest/301/F
题解:就是个简单dp,比赛时没去看这道题,其实这道题比B题还好做,B题因为时原题,所以很多人直接交个编程上去就A了,导致我以为B题更容易,从这次也总结了一点,对于过题数差那么几十题的,都应该去看看。
代码:
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long LL;
const LL mod=1000000007;
const int maxn=210;
LL dp[maxn][maxn][maxn]; ///dp[i][j][step],表示step步到达顶点(i,j)有多少种不同的方案
///马走日,有八个方向
int dir[8][2]={1,2,1,-2,-1,2,-1,-2,2,1,2,-1,-2,1,-2,-1};
int main()
{
int n,m,k;
while(~scanf("%d%d%d",&n,&m,&k))
{
memset(dp,0,sizeof(dp));
dp[0][0][0]=1;
for(int step=1;step<=k;step++)
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
for(int p=0;p<8;p++)
{
int x=i+dir[p][0];
int y=j+dir[p][1];
if(x<0||x>=n||y<0||y>=m) continue;
dp[i][j][step]=(dp[i][j][step]+dp[x][y][step-1])%mod;
}
printf("%lld\n",dp[n-1][m-1][k]);
}
return 0;
}