Leetcode (21)

Source: Internet
Author: User

Paths Unique

Topic

Analysis:

The robot has to go m+n-2 step, now for example analogy, there is a m+n-2 bit of binary number, now in which the M-bit fill 0, the rest of you fill 1, there is a C (m+n-2,m-1) kind of possible, if 0 means down, 1 means go right, so it is the same as the title.

Now consider the last step of the way, either to the right to reach the end, or down to the end, so

F (m,n) = f (m,n-1) +f (m-1,n);

The code is as follows (mainly considering big data):

1 classSolution {2  Public:3     intUniquepaths (intMintN) {4vector<vector<int>> V (M, vector<int> (n,1));5          for(intI=1; i<m; ++i) {6              for(intj=1; j<n; ++j) {7v[i][j]=v[i-1][j]+v[i][j-1];8             }9         }Ten         returnv[m-1][n-1]; One     } A};

Leetcode (21)

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.