这题的标签坑了。。。其实longlong就可以,先确定马能控制的位置,然后再一个一个格子的计算。F(i,j)=f(i-1,j)+f(i,j-1).
#include <iostream> using namespace std; long long x1,y1,x2,y2,p[22][22]; int pan(long long x1,long long y1, long long x2, long long y2) { p[x2][y2]=-1; if (x2+2<=x1&&y2+1<=y1) p[x2+2][y2+1]=-1; if (x2+2<=x1&&y2-1>=1) p[x2+2][y2-1]=-1; if (x2+1<=x1&&y2+2<=y1) p[x2+1][y2+2]=-1; if (x2+1<=x1&&y2-2>=1) p[x2+1][y2-2]=-1; if (x2-1>=1&&y2+2<=y1) p[x2-1][y2+2]=-1; if (x2-1>=1&&y2-2>=1) p[x2-1][y2-2]=-1; if (x2-2>=1&&y2+1<=y1) p[x2-2][y2+1]=-1; if (x2-2>=1&&y2-1>=1) p[x2-2][y2-1]=-1; return 0; } int main() { cin >>x1>>y1>>x2>>y2; x2++; y2++; x1++; y1++; p[1][0]=1; pan(x1,y1,x2,y2); for (long long o1=1;o1<=x1;o1++) for (long long o2=1;o2<=y1;o2++) {if (p[o1][o2]==-1)p[o1][o2]++; else p[o1][o2]=p[o1-1][o2]+p[o1][o2-1];} cout <<p[x1][y1]; return 0; }