[boj] 9461. 파도반 수열 (node.js)

호이·2022년 3월 11일
0

algorithm

목록 보기
39/77
post-thumbnail

문제 요약

[boj] 9461. 파도반 수열 (node.js)

풀이

  • 점화식을 찾아서 풀이하는 DP 문제

내 풀이

const readline = require("readline");
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});

const solution = () => {
  arr = [0, 1, 1, 1, 2, 2, 3, 4, 5, 7, 9];
  for (let i = 11; i <= 100; i++) arr[i] = arr[i - 1] + arr[i - 5];
  const T = input();
  for (let i = 0; i < T; i++) console.log(arr[input()]);
};

let line = 0;
const input = () => stdin[line++];

let stdin = [];
rl.on("line", function (line) {
  stdin.push(line);
}).on("close", function () {
  solution();
  process.exit();
});
  • 오늘은 SQLD 시험 전날이라 간단한 걸로 골라 풀어봤다. 규칙이 간단한 문제라 금방 풀이할 수 있었는데, 문제에서 삼각형 변의 길이를 직접 나열해주지 않았었다면 더 헷갈렸을 수도 있을 것 같다.
profile
매일 부활하는 개복치

0개의 댓글