JadeCode

백준 1010 javascript (node js) 본문

개발/알고리즘

백준 1010 javascript (node js)

z-zero 2022. 1. 14. 20:30

 

//20210114
//다리놓기

//mCn

const input = require("fs")
  .readFileSync("/dev/stdin")
  .toString()
  .trim()
  .split("\n");

// const input = `3
// 2 2
// 1 5
// 13 29
// `.split("\n");

const t = input[0].split(" ").map(Number);

const dp = Array.from({ length: 30 }, () =>
  Array.from({ length: 30 }, () => 0)
);

for (let i = 1; i < 30; i++) {
  for (let j = 1; j < 30; j++) {
    if (i === 1) {
      dp[i][j] = j;
    } else if (i === j) {
      dp[i][j] = 1;
    } else if (j > i) {
      dp[i][j] = dp[i - 1][j - 1] + dp[i][j - 1];
    }
  }
}

// console.log(dp);

for (let i = 1; i <= t; i++) {
  const [n, m] = input[i].split(" ").map(Number);
  console.log(dp[n][m]);
}
Comments