Unique Paths
来源:互联网 发布:装修网络平台有哪些 编辑:程序博客网 时间:2024/05/23 11:41
题目
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?
分析
这是一道动态规划题,状态转移方程为a[i][j] = a[i-1][j] + a[i][j-1]
算法复杂度为O(mn),空间复杂度为O(m)。
代码
class Solution {public: int uniquePaths(int m, int n) { int *a = new int[m]; int i,j; for (i = 0;i < m;i++) a[i] = 1; for (i = 1;i < n;i++) for (j = 1;j < m;j++) a[j] += a[j-1]; return a[m-1]; }};
0 0
- Unique Paths
- Unique Paths
- Unique Paths
- Unique Paths
- Unique Paths
- Unique Paths
- Unique Paths
- Unique Paths
- Unique Paths
- Unique Paths
- Unique Paths
- Unique Paths
- Unique Paths
- Unique Paths
- Unique Paths
- Unique Paths
- Unique Paths
- Unique Paths
- 晶体三极管工作原理讲解方法探讨
- Redis的事务
- 数据库中聚簇索引与非聚簇索引的区别[图文]
- Java面试常考题目
- JavaScript 基本概念之操作符、语句、函数
- Unique Paths
- ubuntu14.04下快速安装搜狗输入法
- Oracle数据库面试练习题
- 微服务理论与实践(三)-微服务架构的基本能力和优缺点
- C++中vptr指针的存在
- 二叉树的各种遍历方法
- JavaWeb初级学习 之 JQuery-简介、选择器
- Sum of Two Integers
- mysql desc asc基本命令总结