Skip to content

Commit

Permalink
#18 22.08.23 > 3 > 계단 오르기;
Browse files Browse the repository at this point in the history
  • Loading branch information
beurmuz committed Aug 23, 2022
1 parent 33abd8b commit 8878162
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/bj/silver/3/2579.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

const [n, ...steps] = require('fs').readFileSync('/dev/stdin').toString().trim().split('\n').map((v) => +v);
const dp = Array(n).fill(0);

dp[0] = steps[0]; // 시작 단계
dp[1] = steps[0] + steps[1]; // 시작 단계 -> 1단계
dp[2] = Math.max(steps[0] + steps[2], steps[1] + steps[2]); // 시작 단계 -> 2단계, 1단계 -> 2단계

for(let i = 3; i < n; i++) {
dp[i] = Math.max(steps[i-1] + steps[i] - dp[i-3], dp[i-2] + steps[i]); // 전전전단계는 제외하고(최대 2칸만 뛸 수 있어서) 전 단계에서 i단계로 오는 방법, 2단계 전에서 i단계로 오는 방법이 있음
}

console.log(dp[n-1]);
3 changes: 2 additions & 1 deletion src/bj/silver/3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
|3|1449|[수리공 항승](./1449.js)|22.08.08|X||
|4|1735|[분수 합](./1735.js)|22.08.10|O||
|5|2193|[이친수](./2193.js)|22.08.17|X||
|6|4948|[베르트랑 공준](./4948.js)|22.08.20|O|
|6|4948|[베르트랑 공준](./4948.js)|22.08.20|O|
|7|2579|[계단 오르기](./2579.js)|22.08.23|X|

0 comments on commit 8878162

Please sign in to comment.