P1002 [NOIP2002 普及组] 过河卒
#include<stdio.h> #include<algorithm> #include<queue> using namespace std; typedef pair<int ,int > p; typedef long long ll; int xa,ya,xm,ym; ll c[22][22]; int v[22][22]; int xx[8]={1,2,-1,2,1,-2,-1,-2}; int yy[8]={2,1,2,-1,-2,1,-2,-1}; int main() { scanf("%d %d %d %d",&xa,&ya,&xm,&ym); v[xm][ym]=1; for(int i=0;i<8;i++) { int xxm=xm+xx[i]; int yym=ym+yy[i]; if(xxm>=0&&xxm<=xa&&yym>=0&&yym<=ya) v[xxm][yym]=1; } for(int i=0;i<=xa;i++) for(int j=0;j<=ya;j++) { if(!v[i][j]) c[i][j]=1; } for(int i=0;i<=xa;i++) for(int j=0;j<=ya;j++) { if(v[i][j]) c[i][j]=0; else if(i==0&&j==0) ; else if(i==0)//处理边界 { c[i][j]=c[i][j-1]; } else if(j==0) { c[i][j]=c[i-1][j]; } else c[i][j]=c[i-1][j]+c[i][j-1]; } printf("%lld\n",c[xa][ya]); }
https://www.luogu.com.cn/problem/P1002
浙公网安备 33010602011771号