File tree 2 files changed +38
-0
lines changed
2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change
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 ]]))
Original file line number Diff line number Diff line change 42
42
| 38μ°¨μ | 2023.02.15 | DP | <a href =" https://www.acmicpc.net/problem/2749 " >νΌλ³΄λμΉ μ 3</a > | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/137
43
43
| 39μ°¨μ | 2023.02.18 | DP | <a href =" https://www.acmicpc.net/problem/7579 " >μ±</a > | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/139
44
44
| 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
45
46
---
You canβt perform that action at this time.
0 commit comments