File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed
Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ A = input ()
2+ B = input ()
3+
4+ N = len (A )
5+ M = len (B )
6+
7+ dp = [[0 ] * (M + 1 ) for _ in range (N + 1 )]
8+
9+ for i in range (1 , N + 1 ):
10+ for j in range (1 , M + 1 ):
11+ if A [i - 1 ] == B [j - 1 ]:
12+ dp [i ][j ] = dp [i - 1 ][j - 1 ] + 1
13+ else :
14+ dp [i ][j ] = max (dp [i - 1 ][j ], dp [i ][j - 1 ])
15+
16+ print (dp [- 1 ][- 1 ])
Original file line number Diff line number Diff line change 1+ # [ Gold V] LCS - 9251
2+
3+ [ 문제 링크] ( https://www.acmicpc.net/problem/9251 )
4+
5+ ### 성능 요약
6+
7+ 메모리: 118572 KB, 시간: 120 ms
8+
9+ ### 분류
10+
11+ 다이나믹 프로그래밍, 문자열
12+
13+ ### 제출 일자
14+
15+ 2025년 4월 23일 13:52:11
16+
17+ ### 문제 설명
18+
19+ <p >LCS(Longest Common Subsequence, 최장 공통 부분 수열)문제는 두 수열이 주어졌을 때, 모두의 부분 수열이 되는 수열 중 가장 긴 것을 찾는 문제이다.</p >
20+
21+ <p >예를 들어, ACAYKP와 CAPCAK의 LCS는 ACAK가 된다.</p >
22+
23+ ### 입력
24+
25+ <p >첫째 줄과 둘째 줄에 두 문자열이 주어진다. 문자열은 알파벳 대문자로만 이루어져 있으며, 최대 1000글자로 이루어져 있다.</p >
26+
27+ ### 출력
28+
29+ <p >첫째 줄에 입력으로 주어진 두 문자열의 LCS의 길이를 출력한다.</p >
30+
You can’t perform that action at this time.
0 commit comments