问题描述
笔记
设置buff[i][j]为到i,j有多少条不同的路径,则状态转移方程为
buff[i][j] = buff[i-1][j] + buff[i][j-1]
初始化:
buff[i][0] = 1;
buff[0][j] = 1;
代码
class Solution {
public:
/**
* @param n, m: positive integer (1 <= n ,m <= 100)
* @return an integer
*/
int uniquePaths(int m, int n) {
// wirte your code here
vector<vector<int>> buff(m, vector<int>(n, 1));
for (int i = 1; i < m; i++)
{
for (int j = 1; j < n; j++)
{
buff[i][j] = buff[i-1][j] + buff[i][j-1];
}
}
return buff[m-1][n-1];
}
};