Unique Paths
来源:互联网 发布:csgo弹道优化参数128 编辑:程序博客网 时间:2024/05/01 21:09
好吧我知道用组合数学可以做!
但是我就想用计算机让他算来着,思想简单,helper(m, n, i, j)表示从(i, j)这个位置到终点有多少种走法,由于从每个点出发只有两条路,因此用分类计数法,把这两条路上可走路径加起来,就得到了从(i, j)出发所有可能的路径。
记得用DP就好。
class Solution {public:int map[101][101];int uniquePaths(int m, int n) {for (int i = 0; i < 101; ++i) for (int j = 0; j < 101; ++j) map[i][j] = -1;return helper(m, n, 0, 0);}int helper(int m, int n, int i, int j) {if (map[i][j] != -1)return map[i][j];if (i == m - 1 && j == n - 1) {map[i][j] = 1;return 1;}if (i >= m || j >= n) {map[i][j] = 0;return 0;}map[i][j] = helper(m, n, i, j + 1) + helper(m, n, i + 1, j);return map[i][j];}};
http://oj.leetcode.com/problems/unique-paths/
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
- Developing Excel Utilities with VBA 章节翻译
- 以复杂结构体为参数在子函数中进行赋值,并返回值给主函数
- ubuntu 配置samba 与windows建立共享的所出现问题
- IOS6后的didReceiveMemoryWarning方法笔记
- 活动召集服务端设计
- Unique Paths
- 黑马程序员_java高级篇反射Day11
- Android应用程序的数据存放目录解说
- linux 之wc命令---linux文件内容统计命令
- Python 学习入门(29)—— 消息队列
- OS X中显示与隐藏文件的方法
- JAVA 泛型编程 JAVA 类泛型编程 JAVA泛型讲解 .
- jdom 操作xml
- 第十二章 人机猜拳小游戏