Algorithm
- 1, 2, 3 ๋ํ๊ธฐ -
๋ฌธ์
์ ์ 4๋ฅผ 1, 2, 3์ ํฉ์ผ๋ก ๋ํ๋ด๋ ๋ฐฉ๋ฒ์ ์ด 7๊ฐ์ง๊ฐ ์๋ค. ํฉ์ ๋ํ๋ผ ๋๋ ์๋ฅผ 1๊ฐ ์ด์ ์ฌ์ฉํด์ผ ํ๋ค.
- 1+1+1+1
- 1+1+2
- 1+2+1
- 2+1+1
- 2+2
- 1+3
- 3+1
์ ์ n์ด ์ฃผ์ด์ก์ ๋, n์ 1, 2, 3์ ํฉ์ผ๋ก ๋ํ๋ด๋ ๋ฐฉ๋ฒ์ ์๋ฅผ ๊ตฌํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ์์ค.
์ ์ถ๋ ฅ ์์
๋ฌธ์ ํ๊ธฐ
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
let input = [];
rl.on("line", function (line) {
input.push(line.toString());
}).on("close", function () {
input.shift();
let values = [...Array(11)];
values[1] = 1;
values[2] = 2;
values[3] = 4;
let fillValues = (num) =>
(values[num] = values[num - 1] + values[num - 2] + values[num - 3]);
for (let i = 4; i <= 10; i++) {
fillValues(i);
}
input.forEach((el) => console.log(values[+el]));
process.exit();
});
๋ฐ์ํ
'๊ฐ์ธ๊ณต๋ถ > Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค][Node.js] 9325๋ฒ : ์ผ๋ง? (0) | 2021.12.23 |
---|---|
[๋ฐฑ์ค][Node.js] 9295๋ฒ : ์ฃผ์ฌ์ (0) | 2021.12.22 |
[๋ฐฑ์ค][Node.js] 9093๋ฒ : ๋จ์ด ๋ค์ง๊ธฐ (0) | 2021.12.21 |
[๋ฐฑ์ค][Node.js] 9086๋ฒ : ๋ฌธ์์ด (0) | 2021.12.19 |
[๋ฐฑ์ค][Node.js] 9085๋ฒ : ๋ํ๊ธฐ (0) | 2021.12.18 |
๋๊ธ