【DP】一共有多少种走法
来源:互联网 发布:java 字符串数组排序 编辑:程序博客网 时间:2024/06/02 13:24
题目描述
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.
递推式:到grid[i][j]有两种走法,从上面走下来,从左边走过来。
所以gridNum[i][j]=gridNum[i-1][j]+gridNum[i][j-1];
矩阵第一行跟第一列均为1。
public class Solution { public int uniquePaths(int m, int n) { int [][] gridNum = new int [m][n]; for(int i = 0;i < m; ++i) gridNum[i][0] = 1; for(int i = 0; i < n; ++i) gridNum[0][i] = 1; for(int i = 1; i < m; ++i){ for(int k = 1; k < n; ++k){ gridNum[i][k] = gridNum[i - 1][k] + gridNum[i][k - 1]; } } return gridNum[m - 1][n - 1]; }}
阅读全文
0 0
- 【DP】一共有多少种走法
- 一共有多少条鱼?
- 中国字一共有多少个?
- 一共有多少个三角形
- 自从盘古开天地 中国一共有多少神仙?
- 世界上一共有多少种编程语言?
- 世界上一共有多少个理发师
- n!一共有多少位长度
- 全世界一共有多少个IP地址?
- 有N个台阶,可以走两步也可以走一步 一共有多少种走法
- N阶台阶,每次只能走一个台阶或者两个台阶,求一共有多少种走法?
- 查看一个或多个文件一共有多少行
- 算出N的阶乘(N!)一共有多少位
- 从a中选出b,一共有多少种选法
- Swift - 计算当月、任意月一共有多少天
- 求从0到n一共有多少个1
- 鸡兔同笼:笼子里一共有鸡和兔子35只,一共有94条退, 笼子里一共有鸡和兔子共多少只
- 新闻联播一共多少集
- Redis-数据结构-整数集合-intset
- vb.net 教程 12-6 webbrowser 文本编辑器 1
- ActiveMQ Master/Slave 集群配置
- 事件流中的事件冒泡
- 全文检索之sphinx源码分析--检索流程
- 【DP】一共有多少种走法
- 爬虫实战10—日志、守护线程以及验证码处理
- Qt Widgets
- org.hibernate.StaleStateException
- Cannot assign a device to node
- 51nod 1137 矩阵乘法
- magent编译报错error: event.h: No such file or directory
- Linux驱动中的platform总线分析
- 二分查找(模板)