
문제 요약
입력
2
1
3
2
3
출력
6
10
문제 분석
2 // T의 수
1 // k,층
3 // n,호
2 // k,층
3 // n,호
undefined 문제가 일어나지 않는다.문제 설계
const fs = require('fs');
const input = fs.readFileSync("/dev/stdin").toString().trim().split("\n");
const [i, ...arr] = input;
const dp = Array.from(Array(15), () => Array(15).fill(0));
for (let i = 0; i < dp.length; i++) {
dp[0][i] = i;
}
for (let i = 1; i < dp.length; i++) {
for (let j = 1; j < dp.length; j++) {
dp[i][j] = dp[i][j - 1] + dp[i - 1][j];
}
}
for (let t = 0; t < i; t++) {
const k = arr[t * 2]; // 층
const n = arr[t * 2 + 1]; // 호
console.log(dp[k][n]);
}
2차원 배열 생성 및 0층 초기화하기 Array.from fill
const dp = Array.from(Array(15), () => Array(15).fill(0));
for (let i = 0; i < dp.length; i++) {
dp[0][i] = i;
}
점화식 세우기 for문

for (let i = 1; i < dp.length; i++) {
for (let j = 1; j < dp.length; j++) {
dp[i][j] = dp[i][j - 1] + dp[i - 1][j];
}
}
해당 테스트 케이스의 층 호를 출력 for 문
for (let t = 0; t < i; t++) {
const k = arr[t * 2]; // 층
const n = arr[t * 2 + 1]; // 호
console.log(dp[k][n]);
}
결론
규칙은 쉽게 찾았는데, 배열의 초기화를 제대로하지못해 배열을 못 찾는 이슈로 많이 틀렸다... 설계와 흐름이 어색하지않게끔 자꾸 연습해야겠다.