From 6d36a3da0f0d433bddf818a98b43c08e09ae21b7 Mon Sep 17 00:00:00 2001 From: tgyuu-An Date: Mon, 4 Mar 2024 18:21:12 +0900 Subject: [PATCH] 2024-03-04 --- ...20\353\221\220\353\202\230\353\254\264.py" | 37 +++++++++++++++++++ tgyuuAn/README.md | 1 + 2 files changed, 38 insertions(+) create mode 100644 "tgyuuAn/DP/\354\236\220\353\221\220\353\202\230\353\254\264.py" diff --git "a/tgyuuAn/DP/\354\236\220\353\221\220\353\202\230\353\254\264.py" "b/tgyuuAn/DP/\354\236\220\353\221\220\353\202\230\353\254\264.py" new file mode 100644 index 00000000..051a4cde --- /dev/null +++ "b/tgyuuAn/DP/\354\236\220\353\221\220\353\202\230\353\254\264.py" @@ -0,0 +1,37 @@ +import sys + +def input(): return sys.stdin.readline() + +T, W = map(int,input().split()) + +# DP[i][j][k] i초에 [j]위치에 있고 [k]번의 횟수를 이동했을 때 받을 수 있는 자두 수 +DP = [[[0 for _ in range(W+1)] for _ in range(2+1)] for _ in range(T+1)] + +plums = [] +for _ in range(T): + plums.append(int(input())) + +for time, plum in zip(range(1,T+1), plums): + + for k in range(W+1): + if k == 0: + if plum == 1: + DP[time][1][k] = DP[time-1][1][k]+1 + DP[time][2][k] = DP[time-1][2][k] + + else: + DP[time][1][k] = DP[time-1][1][k] + DP[time][2][k] = DP[time-1][2][k]+1 + continue + + if plum == 1: + DP[time][1][k] = max(DP[time-1][1][k],DP[time-1][2][k-1])+1 + DP[time][2][k] = max(DP[time-1][1][k-1],DP[time-1][2][k]) + + else: + DP[time][1][k] = max(DP[time-1][1][k],DP[time-1][2][k-1]) + DP[time][2][k] = max(DP[time-1][1][k-1],DP[time-1][2][k])+1 + + DP[time][2][0] = 0 + +print(max([max(x) for x in DP[-1]])) \ No newline at end of file diff --git a/tgyuuAn/README.md b/tgyuuAn/README.md index 530f4f4a..f608a203 100644 --- a/tgyuuAn/README.md +++ b/tgyuuAn/README.md @@ -42,4 +42,5 @@ | 38차시 | 2023.02.15 | DP | 피보나치 수 3 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/137 | 39차시 | 2023.02.18 | DP | | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/139 | 40차시 | 2023.02.21 | DP | 입대 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/142 +| 41차시 | 2023.03.04 | DP | 자두나무 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/148 ---