728x90
문제
https://www.acmicpc.net/problem/15989
코드
const input = require("fs")
.readFileSync(
process.platform === "linux" ? "/dev/stdin" : __dirname + "/example.txt"
)
.toString()
.trim()
.split("\n")
.map((e) => e.trim());
const n = +input.shift();
const arr = input.map(Number);
const max = Math.max(...arr);
const dp = Array.from({ length: max + 1 }, () => 1);
let answer = "";
for (let i = 2; i < dp.length; i++) {
dp[i] += dp[i - 2];
}
for (let i = 3; i < dp.length; i++) {
dp[i] += dp[i - 3];
}
for (let t of arr) {
answer += `${dp[t]}\n`;
}
console.log(answer);
728x90
'코딩 테스트 > 백준' 카테고리의 다른 글
[JS] 쉬운 최단거리 (0) | 2025.04.18 |
---|---|
[JS] 겹치는 건 싫어 (0) | 2025.04.17 |
[JS] 랭킹전 대기열 (0) | 2025.04.11 |
[JS] 12919_A와 B 2 (0) | 2025.04.10 |
[JS] 4659_비밀번호 발음하기 (0) | 2025.04.08 |