首页 > 其他分享 >62. Unique Paths

62. Unique Paths

时间:2022-09-28 11:03:17浏览次数:48  
标签:Paths Right int there 62 right grid corner Unique


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?

 

62. Unique Paths_i++

 

Above is a 7 x 3 grid. How many possible unique paths are there?

Note: m and n will be at most 100.

Example 1:

Input: m = 3, n = 2
Output: 3
Explanation:
From the top-left corner, there are a total of 3 ways to reach the bottom-right corner:
1. Right -> Right -> Down
2. Right -> Down -> Right
3. Down -> Right -> Right
Example 2:

Input: m = 7, n = 3
Output: 28

 

class Solution {
public:
int uniquePaths(int m, int n) {
int a[m][n];
for(int i=0;i<m;i++)
a[i][0]=1;

for(int i=0;i<n;i++)
a[0][i]=1;


for(int i=1;i<m;i++)
for(int j=1;j<n;j++)
a[i][j]=a[i][j-1]+a[i-1][j];

return a[m-1][n-1];


}
};

 

标签:Paths,Right,int,there,62,right,grid,corner,Unique
From: https://blog.51cto.com/u_12504263/5718749

相关文章

  • 高性价比蓝牙/2.4G芯片PHY6252在智慧照明应用
    在未来的很长一段时间内,智慧照明都将是整个物联网的重要发展领域。现在还只是智慧照明发展的初期,很多应用场景都还处在探索阶段,适应物联网时代需求的芯片必须是远高于目前......
  • Many Many Paths(组合计数)
    题意给定\(r1,c1,r2,c2\),求\(\sum\limits_{i=r1}^{r2}\sum\limits_{j=c1}^{c2}f(i,j)\),其中\(f(i,j)\)表示从\((0,0)\)往上或者往右走到\((i,j)\)的方案数。题目链......
  • [CF1562E]Rescue Niwen!
    做题时间:2022.9.22\(【题目描述】\)多组数据,每组数据给定一个字符串\(s(|s|\leq5000,\sum|s|\leq10^4)\),将\(s\)的所有子串排序,按照在\(s\)中出现的位置\(l,r\)......
  • SOJ1626 方珍 题解
    传送门题意给定一个\(n×n\)的方阵,其中第\(i\)行为\(A_{i,1},A_{i,2},...,A_{i,n}\)。对于\(A_i\)的所有区间,设\(f_i\)为其中第\(k_i\)大的\(mex\)值。给......
  • 162. 寻找峰值
    162.寻找峰值峰值元素是指其值严格大于左右相邻值的元素。给你一个整数数组 nums,找到峰值元素并返回其索引。数组可能包含多个峰值,在这种情况下,返回任何一个峰值......
  • LOJ #162. 快速幂 2
    题意要求一个\(O(\sqrtP)-O(1)\)的快速幂。幂可以用扩展欧拉定理规约到\([1,P-1]\)中。分析分块。定个阈值\(B=\sqrtP\)+1。\(a^t=a^{t\bmodB}\cdot......
  • feign.RetryableException: iZuf627hz8vloz1wtzgxzdZ executing GET http://ip-servic
    问题就是通过feign调用接口的时候,去注册中心获取服务位置的时候,拿了服务器的实例名,这是微服务没法处理服务提供者这样配置eureka.instance.prefer-ip-address=trueeure......
  • CF627F Island Puzzle.
    容易观察到一次操作是将\(0\)移动到一个相邻的节点上,而且操作可逆转。所以对于不加边的情况方案是唯一的,直接模拟一下看看是不是相等的就好。对于加一条边来说,我们先将......
  • 【解题报告】SP10628 COT-Count on a tree
    SP10628COT这道题的传送门双倍经验,两个题一样的啦简要题意给出一颗n个节点的树,每个节点都有一个权值,求u到v的第k小权值其实就是树上的区间第k小主席树+树上差分......
  • std:move() 作用 和 移动语义后 右值行为,unique_ptr的"移动"操作问题
    unique_ptr不能进行赋值操作,但是可以有返回unique_ptr的函数,由此产生的问题: 结论1:std:move()只是将一个实参强行转换为右值引用。我们知道对象初始化时有构造函数,拷......