P1002 [NOIP2002 普及组] 过河卒
#include<iostream>
using namespace std;
long long f[400][400],x1,y1,x2,y2;
int check[10][3];
int main() {
cin>>x2>>y2>>x1>>y1;
check[1][1]=x1,check[1][2]=y1,check[2][1]=x1-2,check[2][2]=y1+1,check[3][1]=x1-2,check[3][2]=y1-1;
check[4][1]=x1-1,check[4][2]=y1-2,check[5][1]=x1-1,check[5][2]=y1+2;
check[6][1]=x1+1,check[6][2]=y1-2,check[7][1]=x1+1,check[7][2]=y1+2;
check[8][1]=x1+2,check[8][2]=y1-1,check[9][1]=x1+2,check[9][2]=y1+1;
f[0][0]=1;
for(int i=0; i<=x2; i++) {
for(int j=0; j<=y2; j++) {
bool flag=true;
for(int k=1; k<=9; k++) {
if(i!=check[k][1]||j!=check[k][2])continue;
else {
flag=false;
break;
}
}
if(flag) {
if(i-1>=0)f[i][j]+=f[i-1][j];
if(j-1>=0)f[i][j]+=f[i][j-1];
if(i==0||j==0) {
f[i][j]=1;
}
}
}
}
cout<<f[x2][y2];
}