In the matrix of the following 8*6, calculate the move from a to B altogether there are __ methods. Requires only one cell to move up or to the right at a time, and cannot go through p.
a:456
b:492
c:568
d:626
e:680
f:702
Analytical:
8*6 matrix, from the lower left corner a to the upper right B, altogether need to walk 12 steps, of which 5 steps upward, 7 steps to the right, so the total walk method a total of C (12,5) = 792 kinds, but the topic provisions can not go through p, so need to subtract through the P-point method.
The path through P is divided into two parts, from a to P, from p to B.
Similarly, the way from A to P: C (6,2) = 15;
Similarly, the method of moving from P to B: C (6,3) = 20;
So the way from A to B goes through P-point, there are 15*20=300 species,
So there are 792-300 = 492 ways to go from a to B without the P point.
This problem can actually be calculated using a program.
Simple, dynamic planning
DP[I][J] = Dp[i][j-1] + dp[i-1][j];
The code is as follows:
#include <iostream>#include <cstdio>#include <algorithm>#include <string>using namespace STD;intMain () {intdp[ -][ -] = {0}; for(inti =1; I <=6; i++) for(intj =1; J <=8; J + +) {Dp[i][j] = dp[i-1][J] + dp[i][j-1]; }intdp2[ -][ -] = {0}; dp2[0][1] =1; for(inti =1; I <=4; i++) for(intj =1; J <=4; J + +) Dp2[i][j] = dp2[i-1][J] + dp2[i][j-1];cout<<dp[6][8]-dp2[4][4] * dp[3][5]<<endl;return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
In the matrix of the following 8*6, calculate from a move to B altogether there are ____ species to go. Requires only one cell to move up or to the right at a time, and cannot go through p.