[LeetCode-interview algorithm classic-Java implementation] [062-Unique Paths (Unique path)], leetcode -- java

Source: Internet
Author: User

[LeetCode-interview algorithm classic-Java implementation] [062-Unique Paths (Unique path)], leetcode -- java
[062-Unique Paths (Unique path )][LeetCode-interview algorithm classic-Java implementation] [directory indexes for all questions]Original question

A robot is located at the top-left corner ofm x nGrid (marked 'start' in the dimo-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 dimo-below ).
How many possible unique paths are there?
  
Above is a 3x7 grid. How many possible unique paths are there?
  Note:M and n will be at most 100.

Theme

A robot is located in the upper left corner of the m * n square.
A robot can only go down to the right or both sides of a square. The robot must go to the bottom right corner of the square.
How many unique paths are there.
  Note:M and n cannot exceed 100.

Solutions

Typical dynamic planning problems are solved using the dynamic planning method.
Save the result with m * n group.
For elements in array.
1. When x = 0 or y = 0, A [x] [y] = 1;
2. When x> = 1 and y> = 1 there is A [\ x] [\ y] = A [x-1] [y] + A [\ x] [Y-1].
3. The requested node is A [s-1] [n-1].

Code Implementation

Algorithm Implementation class

Public class Solution {public int uniquePaths (int m, int n) {int [] [] result = new int [m] [n]; // The solution of the first column for (int I = 0; I <m; I ++) {result [I] [0] = 1 ;} // The solution of the first line for (int I = 1; I <n; I ++) {result [0] [I] = 1 ;} // solutions for other locations (int I = 1; I <m; I ++) {for (int j = 1; j <n; j ++) {result [I] [j] = result [I-1] [j] + result [I] [j-1];} // return result [m-1] [n-1];}
Evaluation Result

  Click the image. If you do not release the image, drag it to a position. After the image is released, you can view the complete image in the new window.

Note Please refer to the following link for more information: http://blog.csdn.net/derrantcm/article/details/4252719]

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.