Skip to content

Commit

Permalink
16-퇴사
Browse files Browse the repository at this point in the history
  • Loading branch information
minbr0ther committed Mar 29, 2022
1 parent 6803311 commit da23e18
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
24 changes: 24 additions & 0 deletions 2022/dynamic-programming/13~18/16-퇴사/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');

const n = +input.shift();
const arr = input.map((str) => str.split(' ').map(Number));

const dp = new Array(n).fill(0);

for (let i = 0; i < n; i++) {
const [needDay, income] = arr[i];

if (i + needDay > n) continue;

dp[i] += income;

for (let j = i + needDay; j < n; j++) {
dp[j] = Math.max(dp[i], dp[j]);
}

console.log(dp);
}

console.log(Math.max(...dp));
11 changes: 11 additions & 0 deletions 2022/dynamic-programming/13~18/16-퇴사/input.txt
@@ -0,0 +1,11 @@
10
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10

0 comments on commit da23e18

Please sign in to comment.