Skip to content

Commit

Permalink
Merge pull request #148 from AlgoLeadMe/41-tgyuuAn
Browse files Browse the repository at this point in the history
41-tgyuuAn
  • Loading branch information
tgyuuAn authored Mar 10, 2024
2 parents 512b3bf + 6d36a3d commit dc35c20
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tgyuuAn/DP/μžλ‘λ‚˜λ¬΄.py
Original file line number Diff line number Diff line change
@@ -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]]))
1 change: 1 addition & 0 deletions tgyuuAn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@
| 38μ°¨μ‹œ | 2023.02.15 | DP | <a href="https://www.acmicpc.net/problem/2749">ν”Όλ³΄λ‚˜μΉ˜ 수 3</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/137
| 39μ°¨μ‹œ | 2023.02.18 | DP | <a href="https://www.acmicpc.net/problem/7579">μ•±</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/139
| 40μ°¨μ‹œ | 2023.02.21 | DP | <a href="https://www.acmicpc.net/problem/31413">μž…λŒ€</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/142
| 41μ°¨μ‹œ | 2023.03.04 | DP | <a href="https://www.acmicpc.net/problem/2240">μžλ‘λ‚˜λ¬΄</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/148
---

0 comments on commit dc35c20

Please sign in to comment.