Skip to content

Commit 31a478c

Browse files
[BOJ] 17070 파이프옮기기1 (G5)
1 parent 4285d41 commit 31a478c

File tree

2 files changed

+42
-9
lines changed

2 files changed

+42
-9
lines changed

서정우/4주차/260121.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const fs = require("fs");
2+
const filePath = process.platform === "linux" ? "/dev/stdin" : "./서정우/input.txt";
3+
const input = fs.readFileSync(filePath).toString().trim().split("\n");
4+
5+
const N = Number(input[0]);
6+
const map = input.slice(1).map((line) => line.split(" ").map(Number));
7+
const dp = Array.from({ length: N }, () => Array.from({ length: N }, () => Array(3).fill(0)));
8+
dp[0][0][0] = 0;
9+
dp[0][1][0] = 1;
10+
11+
for (let i = 0; i < N; i++) {
12+
for (let j = 0; j < N; j++) {
13+
// d: 0 = 오른쪽 1 = 대각선 2 = 아래
14+
if (i === 0) {
15+
if (j > 1 && map[i][j] === 0) {
16+
dp[i][j][0] = dp[i][j - 1][0];
17+
}
18+
continue;
19+
}
20+
21+
if (j > 0 && map[i][j] === 0) {
22+
dp[i][j][0] = dp[i][j - 1][0] + dp[i][j - 1][1];
23+
}
24+
25+
if (i > 0 && j > 0 && map[i - 1][j] === 0 && map[i][j] === 0 && map[i][j - 1] === 0) {
26+
dp[i][j][1] = dp[i - 1][j - 1][0] + dp[i - 1][j - 1][1] + dp[i - 1][j - 1][2];
27+
}
28+
29+
if (i > 0 && map[i][j] === 0) {
30+
dp[i][j][2] = dp[i - 1][j][1] + dp[i - 1][j][2];
31+
}
32+
}
33+
}
34+
35+
console.log(dp[N - 1][N - 1].reduce((a, b) => a + b, 0));

서정우/input.txt

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
8 30 4 30
2-
7
3-
9
4-
7
5-
30
6-
2
7-
7
8-
9
9-
25
1+
6
2+
0 0 0 0 0 0
3+
0 1 0 0 0 0
4+
0 0 0 0 0 0
5+
0 0 0 0 0 0
6+
0 0 0 0 0 0
7+
0 0 0 0 0 0

0 commit comments

Comments
 (0)