题解 | #走方格的方案数#
走方格的方案数
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 let args = []; while(line = await readline()){ let tokens = line.split(' '); let a = parseInt(tokens[0]); let b = parseInt(tokens[1]); args = [a, b] } let n = args[0]; let m = args[1]; // let dp = new Array(n+1).fill(0).map(n1=>new Array(m+1).fill(0).map(m1=>1)) // for(let i=1; i<=n; i++){ // for(let j=1; j<=m; j++){ // if(i==1 && j==1) dp[1][1] = 2; // else if(i==2 && j==1) dp[2][1] = 3; // else if(i==1 && j==2) dp[1][2] = 3; // else dp[i][j] = dp[i][j-1] + dp[i-1][j] // } // } let path=0 function dfs(i,j){ if(i==n && j==m){ path ++ }else{ if(i+1<=n){dfs(i+1,j)} if(j+1<=m){dfs(i,j+1)} } } dfs(0, 0) console.log(path) //return dp[n][m] }()#dp#