|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;
import java.util.Arrays;
public class Main{
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str_1 = br.readLine();
String str_2 = br.readLine();
int size_1 = str_1.length();
int size_2 = str_2.length();
int[][] dp = new int[size_1+1][size_2+1];
for(int i=1; i<=size_1; i++){
for(int j=1; j<=size_2; j++){
if(str_1.charAt(i-1) == str_2.charAt(j-1)){
dp[i][j] = dp[i-1][j-1]+1;
} else {
dp[i][j] = Math.max(dp[i-1][j], dp[i][j-1]);
}
}
}
System.out.println(dp[size_1][size_2]);
}
}
|
cs |
문제 풀이 : yabmoons.tistory.com/113 / melonicedlatte.com/algorithm/2018/03/15/181550.html
'백준 2 > DP' 카테고리의 다른 글
| [백준 9461] 파도반 수열 (Java) (0) | 2021.01.13 |
|---|---|
| [백준 1904] 01타일 (Java) (0) | 2021.01.13 |
| [백준 14501] 퇴사 (C++/Python) (0) | 2020.12.07 |
| [백준 9095] 1,2,3 더하기 (0) | 2020.12.07 |
| [백준 11057] 오르막수 (0) | 2020.12.07 |