"Leetcode-Interview algorithm classic-java Implementation" "062-unique Paths (unique path)"

Source: Internet
Author: User

"062-unique Paths (unique path)" "leetcode-Interview algorithm classic-java Implementation" "All Topics folder Index" Original Question

A robot is located at the Top-left corner of a m x n grid (marked ' Start ' in the diagram below).
The robot can only move either down or right at any point in time. The robot is trying-to-reach the bottom-right corner of the grid (marked ' Finish ' in the diagram below).
How many possible unique paths is there?
  
Above is a 3 x 7 grid. How many possible unique paths is there?


  Note: m and N would be is at most 100.

Main Topic

A robot is in the upper left corner of a m*n square.
The robot can only go down one square to the right or the other, and the robot will reach the lower right corner of the grid.


How many unique paths do you have in common?
  Note:m and n do not exceed 100.

Thinking of solving problems

A typical dynamic programming problem is solved by using the dynamic programming method of the problem.
Save the result with a m*n of group A.
For elements in a array, there are.
1, when x=0 or y=0 when there is a[x][y] = 1;
2, when X>=1 and y>=1 when there is a[\x][\y] = a[x-1][y]+a[\x][y-1].
3. The knot to be asked is a[m-1][n-1].

Code Implementation

Algorithm implementation class

 Public classSolution { Public int uniquepaths(intMintN) {int[[] result =New int[M] [n];//The solution of the first column         for(inti =0; I < m; i++) {result[i][0] =1; }//solution of the first line         for(inti =1; I < n; i++) {result[0][i] =1; }//solutions for other locations         for(inti =1; I < m; i++) { for(intj =1; J < N; J + +) {Result[i][j] = result[i-1][J] + result[i][j-1]; }        }//The solution to be asked        returnResult[m-1][n-1]; }}
Assessment Results

  Click on the picture, the mouse does not release. Drag a position to view the full picture in the new form after you release it.

Special Instructions Welcome reprint. Reprint Please specify the source "http://blog.csdn.net/derrantcm/article/details/47182719"

"Leetcode-Interview algorithm classic-java Implementation" "062-unique Paths (unique path)"

Related Article

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.