We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8a125a3 commit eeb3a55Copy full SHA for eeb3a55
1 file changed
live10/test101/문제2/황장현.js
@@ -0,0 +1,26 @@
1
+const input = require('fs')
2
+ .readFileSync(process.platform === 'linux' ? '/dev/stdin' : './input.txt')
3
+ .toString()
4
+ .trim()
5
+ .split('\n')
6
+ .map((el) => el.split(' ').map(Number));
7
+
8
+function solution(input) {
9
+ const N = input[0][0];
10
+ const cost = input.slice(1);
11
+ const dp = Array.from({ length: N + 1 }, () => Array(3).fill(0));
12
13
+ dp[1][0] = cost[0][0];
14
+ dp[1][1] = cost[0][1];
15
+ dp[1][2] = cost[0][2];
16
17
+ for (let i = 2; i <= N; i++) {
18
+ dp[i][0] = cost[i - 1][0] + Math.min(dp[i - 1][1], dp[i - 1][2]);
19
+ dp[i][1] = cost[i - 1][1] + Math.min(dp[i - 1][0], dp[i - 1][2]);
20
+ dp[i][2] = cost[i - 1][2] + Math.min(dp[i - 1][0], dp[i - 1][1]);
21
+ }
22
23
+ return Math.min(dp[N][0], dp[N][1], dp[N][2]);
24
+}
25
26
+console.log(solution(input));
0 commit comments