Skip to content

Commit dc35c20

Browse files
authored
Merge pull request #148 from AlgoLeadMe/41-tgyuuAn
41-tgyuuAn
2 parents 512b3bf + 6d36a3d commit dc35c20

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import sys
2+
3+
def input(): return sys.stdin.readline()
4+
5+
T, W = map(int,input().split())
6+
7+
# DP[i][j][k] iμ΄ˆμ— [j]μœ„μΉ˜μ— 있고 [k]번의 횟수λ₯Ό μ΄λ™ν–ˆμ„ λ•Œ 받을 수 μžˆλŠ” μžλ‘ 수
8+
DP = [[[0 for _ in range(W+1)] for _ in range(2+1)] for _ in range(T+1)]
9+
10+
plums = []
11+
for _ in range(T):
12+
plums.append(int(input()))
13+
14+
for time, plum in zip(range(1,T+1), plums):
15+
16+
for k in range(W+1):
17+
if k == 0:
18+
if plum == 1:
19+
DP[time][1][k] = DP[time-1][1][k]+1
20+
DP[time][2][k] = DP[time-1][2][k]
21+
22+
else:
23+
DP[time][1][k] = DP[time-1][1][k]
24+
DP[time][2][k] = DP[time-1][2][k]+1
25+
continue
26+
27+
if plum == 1:
28+
DP[time][1][k] = max(DP[time-1][1][k],DP[time-1][2][k-1])+1
29+
DP[time][2][k] = max(DP[time-1][1][k-1],DP[time-1][2][k])
30+
31+
else:
32+
DP[time][1][k] = max(DP[time-1][1][k],DP[time-1][2][k-1])
33+
DP[time][2][k] = max(DP[time-1][1][k-1],DP[time-1][2][k])+1
34+
35+
DP[time][2][0] = 0
36+
37+
print(max([max(x) for x in DP[-1]]))

β€ŽtgyuuAn/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,5 @@
4242
| 38μ°¨μ‹œ | 2023.02.15 | DP | <a href="https://www.acmicpc.net/problem/2749">ν”Όλ³΄λ‚˜μΉ˜ 수 3</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/137
4343
| 39μ°¨μ‹œ | 2023.02.18 | DP | <a href="https://www.acmicpc.net/problem/7579">μ•±</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/139
4444
| 40μ°¨μ‹œ | 2023.02.21 | DP | <a href="https://www.acmicpc.net/problem/31413">μž…λŒ€</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/142
45+
| 41μ°¨μ‹œ | 2023.03.04 | DP | <a href="https://www.acmicpc.net/problem/2240">μžλ‘λ‚˜λ¬΄</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/148
4546
---

0 commit comments

Comments
Β (0)