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.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.