【LeetCode】62.Unique Paths解题报告
来源:互联网 发布:directx 11游戏编程 编辑:程序博客网 时间:2024/05/16 18:48
【LeetCode】62.Unique Paths解题报告
tags: Array DP
题目地址:https://leetcode.com/problems/unique-paths/#/description
题目描述:
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 are there?
Above is a 3 x 7 grid. How many possible unique paths are there?
Note:m and n will be at most 100.
题意:机器人从左顶点走到右顶点,问多少种走法,只能向右和向下。
分析:本题其实就是一个组合问题,用公式可以直接得到,然而,题还可以用dp做,但是刚开始刷题,dp解法以后补上。公式其实就是(m+n)!/m!*n!
Solutions:
public class Solution { public int uniquePaths(int m, int n) { if(m == 1 || n == 1) return 1; m--; n--; if(m < n) { // Swap, so that m is the bigger number m = m + n; n = m - n; m = m - n; } long res = 1; int j = 1; for(int i = m+1; i <= m+n; i++, j++){ // Instead of taking factorial, keep on multiply & divide res *= i; res /= j; } return (int)res; }}
Date:2017年6月23日
阅读全文
0 0
- [leetcode] 62. Unique Paths 解题报告
- leetcode解题报告:62. Unique Paths
- [Leetcode] 62. Unique Paths 解题报告
- 【LeetCode】62.Unique Paths解题报告
- 【LeetCode】Unique Paths 解题报告
- [LeetCode] Unique Paths 解题报告
- Leetcode #62. Unique Paths 路径搜寻 解题报告
- [LeetCode]Unique Paths II, 解题报告
- 【LeetCode】Unique Paths II 解题报告
- LeetCode 62 Unique Paths 解题报告
- [leetcode] 63. Unique Paths II 解题报告
- [LeetCode] Unique Paths II 解题报告
- [Leetcode] 63. Unique Paths II 解题报告
- Leetcode 63. Unique Paths II 路径搜寻2 解题报告
- Leetcode解题笔记 62. Unique Paths [Medium] 动态规划
- [LeetCode]62.Unique Paths
- LeetCode --- 62. Unique Paths
- LeetCode 62.Unique Paths
- 图像语义分割之FCN和CRF
- javaweb学习总结——数据库连接池
- Linux下安装DB2
- wildfly服务器系列--widlfly启动Operation ("add") failed失败以及org.dom4j.DocumentFactory cannot be cast to org.d
- iOS带有缩放效果的自动轮播图
- 【LeetCode】62.Unique Paths解题报告
- concat、reverse方法、随机排序、随机函数
- 设计模式之抽象工厂模式的学习心得
- java 编程中遇到空指针异常的可能原因java.lang.nullpointerexception
- C/C++ 读写文件
- win10 python 3.5.2 安装lightgbm
- BSEG和BSIS、BSAS、BSID、BSAD、BSIK、BSAK六个表的关系(转)
- 多行新闻滚动栏实现
- Codeforces Drinks