题目:一个机器人在m×n大小的地图的左上角(起点)。机器人每次向下或向右移动。机器人要到达地图的右下角(终点)。可以有多少种不同的路径从起点走到终点?
备注:m和n小于等于100,并保证计算结果在int范围内
思路:
代码:
1 var memo = []; 2 for(let i = 0; i < n; i++){ 3 memo.push([]); 4 } 5 for(let row = 0; row < n; row ++){ 6 memo[row][0] = 1; 7 } 8 for(let col = 0; col < m; col++){ 9 memo[0][col] = 1; 10 } 11 for(let row = 1 ; row < n; row++){ 12 for(let col = 1; col < m; col++){ 13 memo[row][col] = memo[row-1][col] + memo[row][col-1]; 14 } 15 } 16 return memo[n-1][m-1];
原文:https://www.cnblogs.com/icyyyy/p/14801350.html