1 #include<stdio.h> 2 int main() 3 { 4 int desk[101][101]={0}; 5 int i,j,m,n; 6 int hx,hy; 7 scanf("%d%d",&m,&n); 8 scanf("%d%d",&hx,&hy); 9 desk[hx][hy]=-1; 10 if(hx+2<=m) //优化算法什么的都去死吧 11 if(hy+1<=n) desk[hx+2][hy+1]=-1; 12 if(hy-1>=0) desk[hx+2][hy-1]=-1; 13 if(hx+1<=m) 14 if(hy+2<=n) desk[hx+1][hy+2]=-1; 15 if(hy-2>=0) desk[hx+1][hy-2]=-1; 16 if(hx-1>=0) //复制粘贴大法好 17 if(hy+2<=n) desk[hx-1][hy+2]=-1; 18 if(hy-2>=0) desk[hx-1][hy-2]=-1; 19 if(hx-2>=0) 20 if(hy+1<=n) desk[hx-2][hy+1]=-1; 21 if(hy-1>=0) desk[hx-2][hy-1]=-1; 22 23 //调试解调器 24 /* 25 for(i=0;i<=m;i++) 26 { 27 for(j=0;j<=n;j++) 28 desk[i][j]==0?printf("#"):printf("X"); 29 printf(" "); 30 }*/ 31 //调试结束 32 33 desk[0][0]=1; 34 for(i=0;i<=m;i++) 35 { 36 for(j=0;j<=n;j++) 37 { 38 if(desk[i][j]==-1) // 如果是拦截位,跳过操作 39 continue; 40 if(i-1>=0&&desk[i-1][j]!=-1) // 41 desk[i][j]+=desk[i-1][j]; 42 if(j-1>=0&&desk[i][j-1]!=-1) // 43 desk[i][j]+=desk[i][j-1]; 44 } 45 } 46 47 printf("%d",desk[m][n]); 48 //调试解调器 49 50 /* 51 for(i=0;i<=m;i++) 52 { 53 for(j=0;j<=n;j++) 54 desk[i][j]==-1?printf("X "):printf("%d ",desk[i][j]); 55 printf(" "); 56 }*/ 57 //调试结束 58 }
这份代码没有考虑高精度,只有算法内容,一般m n到20就溢出了
问题是,一个m,n的棋盘,有一只马,马和马能走的地方不能过,卒只能向上或向右走,问卒在0,0到m,n多少种走法