比较坑的,注意数据范围,开long long
dp[i][j]表示到达(i,j)点的路径数
#include<bits/stdc++.h> using namespace std; #define int long long int mp[30][30],dp[30][30]; signed main() { int n,m,x,y; cin>>n>>m>>x>>y; mp[x-1][y-2]=1,mp[x-2][y-1]=1,mp[x-1][y+2]=1,mp[x-2][y+1]=1; mp[x+1][y-2]=1,mp[x+1][y+2]=1,mp[x+2][y-1]=1,mp[x+2][y+1]=1; mp[x][y]=1; dp[0][0]=1;//初始化 for(int i=0;i<=n;i++) { for(int j=0;j<=m;j++) { if(!mp[i+1][j]) dp[i+1][j]+=dp[i][j]; if(!mp[i][j+1]) dp[i][j+1]+=dp[i][j]; } } cout<<dp[n][m]; }