From dd15fdaa8b1d18bf7b1a4f04ceca308197d51901 Mon Sep 17 00:00:00 2001 From: SSUM <116950962+ssum21@users.noreply.github.com> Date: Tue, 11 Mar 2025 14:23:06 +0900 Subject: [PATCH] [Gold V] Title: LCS, Time: 488 ms, Memory: 58316 KB -BaekjoonHub --- 백준/Gold/9251. LCS/LCS.py | 24 ++++++++++++++++++++++++ 백준/Gold/9251. LCS/README.md | 30 ++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 백준/Gold/9251. LCS/LCS.py create mode 100644 백준/Gold/9251. LCS/README.md diff --git a/백준/Gold/9251. LCS/LCS.py b/백준/Gold/9251. LCS/LCS.py new file mode 100644 index 0000000..cc1e2de --- /dev/null +++ b/백준/Gold/9251. LCS/LCS.py @@ -0,0 +1,24 @@ +import sys + +input = sys.stdin.readline + +N = list(map(str, input().strip())) +M = list(map(str, input().strip())) + +len_N = len(N) +len_M = len(M) + +arr = [[0 for i in range(len_N+1)] for j in range(len_M+1)] + +tot = 0 +i=0 +j=0 + +for j in range(1, len_M+1): + for i in range(1, len_N+1): + if(N[i-1] == M[j-1]): + arr[j][i] = arr[j-1][i-1] + 1 + else: + arr[j][i] = max(arr[j][i-1], arr[j-1][i]) + +print(arr[len_M][len_N]) \ No newline at end of file diff --git a/백준/Gold/9251. LCS/README.md b/백준/Gold/9251. LCS/README.md new file mode 100644 index 0000000..df9a50d --- /dev/null +++ b/백준/Gold/9251. LCS/README.md @@ -0,0 +1,30 @@ +# [Gold V] LCS - 9251 + +[문제 링크](https://www.acmicpc.net/problem/9251) + +### 성능 요약 + +메모리: 58316 KB, 시간: 488 ms + +### 분류 + +다이나믹 프로그래밍, 문자열 + +### 제출 일자 + +2025년 3월 11일 14:22:36 + +### 문제 설명 + +

LCS(Longest Common Subsequence, 최장 공통 부분 수열)문제는 두 수열이 주어졌을 때, 모두의 부분 수열이 되는 수열 중 가장 긴 것을 찾는 문제이다.

+ +

예를 들어, ACAYKP와 CAPCAK의 LCS는 ACAK가 된다.

+ +### 입력 + +

첫째 줄과 둘째 줄에 두 문자열이 주어진다. 문자열은 알파벳 대문자로만 이루어져 있으며, 최대 1000글자로 이루어져 있다.

+ +### 출력 + +

첫째 줄에 입력으로 주어진 두 문자열의 LCS의 길이를 출력한다.

+