博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LeetCode 62.Unique Paths
阅读量:6938 次
发布时间:2019-06-27

本文共 785 字,大约阅读时间需要 2 分钟。

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?

大致题意

机器人每次只能向下向右走一步,给予一个mxn大小的方格,共有几种方法可以到达右下角(机器人在左上角)

题解

题目类型:动态规划

dp[i][j]表示到达第i行第j列有几种方法,初始为1。

状态转移:dp[i][j] = dp[i - 1][j] + dp[i][j - 1]

下方为解

class Solution {public:    int uniquePaths(int m, int n) {        vector
> path(m, vector
(n, 1)); for (int i = 1; i < m; i++) { for (int j = 1; j < n; j++) { path[i][j] = path[i - 1][j] + path[i][j - 1]; } } return path[m - 1][n - 1]; }};

转载地址:http://qusnl.baihongyu.com/

你可能感兴趣的文章
创新or抄袭?仿苹果OS开源Pear Linux体验(1)
查看>>
mysql配置讲解
查看>>
DRBD+HeartBeat+NFS 搭建高可用文件共享服务器笔记
查看>>
web数据同步的四种方式
查看>>
拼音输入法雏形原理
查看>>
自动打包备份压缩常用的脚步
查看>>
varnish优化
查看>>
zabbix监控apache
查看>>
那些年,我们一起学过的汇编----之“Hello World!”
查看>>
二、lwip协议栈之telnet
查看>>
大家好
查看>>
APACHE动态和静态编译区别
查看>>
音视频封装格式、编码格式知识
查看>>
Linux 系统开启VNC服务
查看>>
一步一步使用Ext JS MVC与Asp.Net MVC 3开发简单的CMS后台管理系统之登录窗口调试...
查看>>
谈谈Ext JS的组件——布局的使用方法
查看>>
python入门书籍
查看>>
雷林鹏分享:CodeIgniter文件上传错误:the filetype you are attempting to upload is not allowed...
查看>>
雷林鹏分享:PHP 命名空间(namespace)
查看>>
Alpha冲刺随笔集
查看>>