From 29d89f5bc127347c265a58d9fffd34c0c92674ea Mon Sep 17 00:00:00 2001 From: yelin Date: Wed, 21 Feb 2024 18:03:50 +0900 Subject: [PATCH] [week-05-dp] 1912, 9251 --- week05-dp/leGit-y/.gitkeep | 0 week05-dp/leGit-y/1912.py | 12 ++++++++++++ week05-dp/leGit-y/9251.py | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+) delete mode 100644 week05-dp/leGit-y/.gitkeep create mode 100644 week05-dp/leGit-y/1912.py create mode 100644 week05-dp/leGit-y/9251.py diff --git a/week05-dp/leGit-y/.gitkeep b/week05-dp/leGit-y/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/week05-dp/leGit-y/1912.py b/week05-dp/leGit-y/1912.py new file mode 100644 index 0000000..a0855c4 --- /dev/null +++ b/week05-dp/leGit-y/1912.py @@ -0,0 +1,12 @@ +import sys +input = sys.stdin.readline +n = int(input()) +arr = list(map(int, input().split())) + + +for i in range(1, n): + arr[i] = max(arr[i], arr[i] + arr[i-1]) + +print(max(arr)) + + diff --git a/week05-dp/leGit-y/9251.py b/week05-dp/leGit-y/9251.py new file mode 100644 index 0000000..8585f5f --- /dev/null +++ b/week05-dp/leGit-y/9251.py @@ -0,0 +1,18 @@ +A = input() +B = input() + +N1 = len(A) +N2 = len(B) + +result = [[0] * (N2+1) for _ in range(N1+1)] + +for i in range(1, N1+1): + for j in range(1, N2+1): + + if A[i-1] == B[j-1]: + result[i][j] = result[i-1][j-1] + 1 + + else: + result[i][j] = max(result[i-1][j], result[i][j-1]) + +print(result[N1][N2])