Skip to content

Commit 8c01edb

Browse files
authored
Merge pull request #1018 from AlgorithmWithGod/LiiNi-coder
[20251001] BOJ / G5 / LCS / 이인희
2 parents fe4cdc0 + 89a2b60 commit 8c01edb

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

LiiNi-coder/202510/01 BOJ LCS.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
public static void main(String[] args) throws IOException {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
String A = br.readLine();
9+
String B = br.readLine();
10+
int n = A.length();
11+
int m = B.length();
12+
13+
int[][] dp = new int[n + 1][m + 1];
14+
for(int i = 1; i <= n; i++) {
15+
for(int j = 1; j <= m; j++) {
16+
if(A.charAt(i - 1) == B.charAt(j - 1)) {
17+
dp[i][j] = dp[i-1][j-1] + 1;
18+
} else {
19+
dp[i][j] = Math.max(dp[i-1][j], dp[i][j- 1]);
20+
}
21+
}
22+
}
23+
System.out.println(dp[n][m]);
24+
}
25+
}
26+
27+
```

0 commit comments

Comments
 (0)