๐ŸŽฒ๋ฐฑ์ค€ 9461๋ฒˆ ํŒŒ๋„๋ฐ˜ ์ˆ˜์—ด

Jeongeunยท2023๋…„ 3์›” 25์ผ
0

๋ฐฑ์ค€

๋ชฉ๋ก ๋ณด๊ธฐ
36/187

๋ฐฑ์ค€ 9461๋ฒˆ

์ฝ”๋“œ

๐Ÿ’ก dp ๋ฐฐ์—ด์— [1, 1, 1, 2, 2]์„ ๋‹ด์•„ ๋†“๊ณ  dp[5]๋ถ€ํ„ฐ ์ ์šฉ๋˜๋Š” ๊ทœ์น™์„ ์ฐพ์•˜๋‹ค.

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

let dp = [1, 1, 1, 2, 2];

const func = (num) => {
  for (let j = 5; j < num; j++) {
    //๊ทœ์น™
    dp[j] = dp[j - 1] + dp[j - 5];
  }
};

//๊ฐ€์žฅ ํฐ ์ž…๋ ฅ๊ฐ’์„ ๋„ฃ์–ด dp ๋ฐฐ์—ด์„ ๋งŒ๋“ค์–ด์ค€๋‹ค.
func(Math.max(...input));

for (let i = 0; i < n; i++) {
  console.log(dp[input[i]-1]);
}

0๊ฐœ์˜ ๋Œ“๊ธ€