原题链接:https://www.luogu.com.cn/problem/P1002
算法标签:动态规划
代码:
#include <iostream>
using namespace std;
int n,m,x,y;
bool book[29][29];
long long dp[29][29];
bool check(int tx, int ty){
if( tx>=0 && tx<=n && ty>=0 && ty<=m ){
return true;
}else{
return false;
}
}
int main(){
cin >> n >> m >> x >> y;
if( check(x, y ) ) book[x ][y ] = true;
if( check(x-1, y-2) ) book[x-1][y-2] = true;
if( check(x-2, y-1) ) book[x-2][y-1] = true;
if( check(x-2, y+1) ) book[x-2][y+1] = true;
if( check(x-1, y+2) ) book[x-1][y+2] = true;
if( check(x+1, y+2) ) book[x+1][y+2] = true;
if( check(x+2, y+1) ) book[x+2][y+1] = true;
if( check(x+2, y-1) ) book[x+2][y-1] = true;
if( check(x+1, y-2) ) book[x+1][y-2] = true;
if( book[0][0] ){
dp[0][0] = 0;
}else{
dp[0][0] = 1;
}
for( int j=1; j<=m; j++ ){
if( book[0][j] ){
dp[0][j] = 0;
}else{
dp[0][j] = dp[0][j-1];
}
}
for( int i=1; i<=n; i++ ){
if( book[i][0] ){
dp[i][0] = 0;
}else{
dp[i][0] = dp[i-1][0];
}
}
for( int i=1; i<=n; i++ ){
for( int j=1; j<=m; j++ ){
if( book[i][j] ){
dp[i][j] = 0;
}else{
dp[i][j] = dp[i][j-1] + dp[i-1][j];
}
}
}
cout << dp[n][m];
return 0;
}