티스토리 뷰
반응형
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package BACKJOON; | |
import java.util.Scanner; | |
public class back_9251 { | |
public static int dp[][]; | |
public static char[] s1; | |
public static char[] s2; | |
public static void main(String[] args) { | |
Scanner sc = new Scanner(System.in); | |
s1 = sc.nextLine().toCharArray(); | |
s2 = sc.nextLine().toCharArray(); | |
dp = new int[s1.length + 1][s2.length + 1]; | |
LCS(s1.length, s2.length); | |
// for(int i=0; i< dp.length; i++){ | |
// for(int j=0; j< dp[i].length; j++) { | |
// System.out.print(dp[i][j]+" "); | |
// } | |
// System.out.println(); | |
// } | |
} | |
public static void LCS(int x, int y) { | |
for (int i = 1; i <= x; i++) { | |
for (int j = 1; j <= y; j++) { | |
if (s1[i - 1] == s2[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[s1.length][s2.length]); | |
} | |
} |

반응형
'알고리즘 > 백준' 카테고리의 다른 글
15649번 백준 (0) | 2021.04.20 |
---|---|
1260번 백준 (0) | 2021.04.20 |
[back_11404] (0) | 2021.03.29 |
[1197]최소 스패닝 트리(MST) / 스패닝 트리(STP) (0) | 2021.02.14 |
[백준] 1330번 두 수 비교하기 (0) | 2021.02.09 |
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 스프링부트
- 면접
- security
- Spring
- Matlab
- CS
- spring-cloud
- 알고리즘
- Solid
- 백준
- kakao
- C언어
- springboot
- java
- 수학
- interview
- docker
- 디자인패턴
- nginx
- 프로그래머스
- 릿코드
- Algorithm
- 매트랩
- 자바
- 그래프
- 자격증
- 스프링
- OOP
- ajax
- JPA
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함