Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=2125
Test instructions: One of the NXM's meshes is broken, asking the number of places from the beginning to the end.
Analysis: Mathematical formulas
If there is no bad side, the total number of methods is CN-1 (m+n-2)
Because each method has to walk (m+n-2) step, walk up N-1 step, walk down M-1 step
Now consider a bad side, then calculate the number of schemes passing through this bad side and subtract from the total
The number of X1 by the bad side is the number of Y1 from the starting point to the (x2, y2) to the end of the method.
#include <cstdio>#include<cstring>#include<cmath>#include<iostream>#include<algorithm>#include<queue>#include<cstdlib>#include<vector>#include<Set>#include<map>#defineLL Long Long#defineMoD 1000000007#defineINF 0x3f3f3f3f#defineN 10010using namespacestd; LL c[ -][ -];voidinit () { for(intI=0; i<= +; i++) c[i][0]=c[i][i]=1; for(intI=1; i<= +; i++) for(intj=1; j<i;j++) c[i][j]=c[i-1][j]+c[i-1][j-1];}intMain () {intN,m,x1,y1,x2,y2; Init (); while(SCANF ("%d%d", &n,&m) >0) {scanf ("%d%d%d%d",&x1,&y1,&x2,&y2); if(x1+y1>x2+y2) {swap (X1,X2); Swap (Y1,Y2); } printf ("%i64d\n", c[n+m-2][m-1]-c[x1+y1][x1]*c[m+n-2-x2-y2][m-1-X2]); }}View Code
hdu2125 (mathematics)