A simple dp,nxm grid where one edge is broken, ask for the number of points from the starting point to the end point
There are two methods, one is DP very well understood
1 //#define LOCAL2#include <cstdio>3#include <cstring>4 5 intdp[ the][ the];6 BOOLflag[ the][ the];7 8 intMainvoid)9 {Ten #ifdef LOCAL OneFreopen ("2125in.txt","R", stdin); A #endif - - intR, C; the while(SCANF ("%d%d", &r, &c) = =2) - { - inty1, x1, y2, x2; -scanf"%d%d%d%d", &y1, &x1, &y2, &x2); +dp[0][1] =1; -memset (Flag,false,sizeof(flag)); +flag[x1+1][y1+1] = flag[x2+1][y2+1] =true; A for(inti =1; I <= R; ++i) at for(intj =1; J <= C; ++j) - { -DP[I][J] = dp[i-1][J] + dp[i][j-1]; - if(Flag[i][j]) - { - if(flag[i][j-1]) inDP[I][J]-= dp[i][j-1]; - if(flag[i-1][j]) toDP[I][J]-= dp[i-1][j]; + } - } theprintf"%d\n", Dp[r][c]); * } $ return 0;Panax Notoginseng}
code June
The second, using a mathematical formula
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.
1 #defineLOCAL2#include <algorithm>3#include <cstdio>4#include <cstring>5 using namespacestd;6 7 Long LongCLong LongMLong LongN)8 {9 if(m==0|| n==0)Ten return 1; Onen = min (n, M-n); A Long LongAns =1; - for(inti =0; I < n; ++i) -Ans = ans * (m-i)/(1+i); the returnans; - } - - intMainvoid) + { - #ifdef LOCAL +Freopen ("2125in.txt","R", stdin); A #endif at - intN, M; - while(SCANF ("%d%d", &n, &m) = =2) - { - intx1, y1, x2, y2; -scanf"%d%d%d%d", &x1, &y1, &X2, &y2); in if(X1+y1 > x2+y2) - { to intt =X1; +x1 = x2, x2 =T; -t =Y1; they1 = y2, y2 =T; * } $printf"%lld\n", C (m+n-2, M-1)-C (x1+y1, x1) * C (m+n-2-x2-y2, M1-x2));Panax Notoginseng } - return 0; the}
code June
HDU 2125 Local Area Network