题解 | #走方格的方案数#
走方格的方案数
https://www.nowcoder.com/practice/e2a22f0305eb4f2f9846e7d644dba09b
动态规划解题 注意是沿着边缘线走 完整代码如下:
const rl = require("readline").createInterface({ input: process.stdin }); var iter = rl[Symbol.asyncIterator](); const readline = async () => (await iter.next()).value; void async function () { // Write your code here while(line = await readline()){ let [m, n] = line.split(' ').map(Number); let dp = Array(m+1).fill(0).map(() => new Array(n+1).fill(1)); for (let i = 1; i <= m; i++) { for (let j = 1; j <= n; j++) { dp[i][j] = dp[i-1][j] + dp[i][j-1] } } console.log(dp[m][n]) } }()