Skip to content

Commit

Permalink
11-포도주-시식
Browse files Browse the repository at this point in the history
  • Loading branch information
minbr0ther committed Mar 10, 2022
1 parent 2d6744f commit 43f96a2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
24 changes: 24 additions & 0 deletions 2022/dynamic-programming/11-포도주-시식/app.js
@@ -0,0 +1,24 @@
const fs = require("fs");
const filePath = process.platform === "linux" ? "/dev/stdin" : "./input.txt";
let input = fs.readFileSync(filePath).toString().trim().split("\n");

let [N, ...arr] = input;
N = +N;
arr = arr.map(Number);
const dy = new Array(N).fill(0);

dy[0] = arr[0];
dy[1] = arr[0] + arr[1];
dy[2] = Math.max(dy[1], dy[0] + arr[2], arr[1] + arr[2]);

for (let i = 3; i < N; i++) {
dy[i] = Math.max(
dy[i - 3] + arr[i - 1] + arr[i],
dy[i - 2] + arr[i],
dy[i - 1]
);
}

console.log(dy[N - 1]);

// 참고: https://junghyeonsu.tistory.com/210
7 changes: 7 additions & 0 deletions 2022/dynamic-programming/11-포도주-시식/input.txt
@@ -0,0 +1,7 @@
6
6
10
13
9
8
1

0 comments on commit 43f96a2

Please sign in to comment.