Skip to content

Commit b58a650

Browse files
committed
[BOJ] #17218. 비밀번호 만들기 / 골드4 / 40분 / 성공
1 parent fa5652a commit b58a650

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
# 입력 및 초기화
5+
S1 = input().strip()
6+
S2 = input().strip()
7+
n, m = len(S1), len(S2)
8+
dp = [[""] * (m+1) for _ in range(n+1)]
9+
10+
# DP 채우기
11+
for i in range(1, n+1):
12+
for j in range(1, m+1):
13+
# 문자가 같으면 이전 값에 현재 문자 더하기
14+
if S1[i-1] == S2[j-1]:
15+
dp[i][j] = dp[i-1][j-1] + S1[i-1]
16+
# 문자가 다르면 더 긴 걸로 선택
17+
else:
18+
if len(dp[i-1][j]) > len(dp[i][j-1]):
19+
dp[i][j] = dp[i-1][j]
20+
else:
21+
dp[i][j] = dp[i][j-1]
22+
23+
# 정답 출력
24+
print(dp[n][m])

0 commit comments

Comments
 (0)