Created
February 15, 2020 04:11
-
-
Save inspirit941/3387fe503ffb4f6cc49b45d05386d608 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def solution(left, right): | |
left.insert(0,0) | |
right.insert(0,0) | |
# table[leftidx][rightidx] = left에서 idx빼낼 때, right에서 idx개 빼낼 때 최댓값. | |
table = [[0 for _ in range(len(right))] for _ in range(len(left))] | |
for y in range(1, len(left)): | |
for x in range(1, len(right)): | |
# 왼쪽 / 오른쪽 카드 둘 다 버리는 경우, 왼쪽 카드만 버리는 경우의 최댓값 | |
table[y][x] = max(table[y-1][x-1], table[y-1][x]) | |
# 오른쪽 카드만 버릴 수 있을 경우 | |
if left[y] > right[x]: | |
table[y][x] = max(table[y][x], table[y][x-1] + right[x]) | |
return table[-1][-1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment