Skip to content

Commit e01dd7d

Browse files
[BOJ] 15482 한글 LCS (G5)
1 parent 12533a6 commit e01dd7d

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

서정우/10주차/260305.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const fs = require("fs");
2+
const filePath = process.platform === "linux" ? "/dev/stdin" : "./서정우/input.txt";
3+
const input = fs
4+
.readFileSync(filePath)
5+
.toString()
6+
.trim()
7+
.split("\n")
8+
.map((el) => el.trim());
9+
10+
const str1 = input[0];
11+
const str2 = input[1];
12+
13+
const set1 = str1.split("");
14+
const set2 = str2.split("");
15+
16+
const dp = Array(set1.length + 1)
17+
.fill(null)
18+
.map(() => Array(set2.length + 1).fill(0));
19+
20+
let max = 0;
21+
22+
for (let i = 1; i <= set1.length; i++) {
23+
for (let j = 1; j <= set2.length; j++) {
24+
const char1 = set1[i - 1];
25+
const char2 = set2[j - 1];
26+
27+
if (char1 === char2) {
28+
dp[i][j] = dp[i - 1][j - 1] + 1;
29+
max = Math.max(dp[i - 1][j - 1] + 1, max);
30+
} else {
31+
dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
32+
max = Math.max(Math.max(dp[i - 1][j], dp[i][j - 1]), max);
33+
}
34+
}
35+
}
36+
37+
console.log(max);

서정우/input.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
5
1+
선데이코딩
2+
딩코이데선

0 commit comments

Comments
 (0)