Skip to content

Commit 8b6ea14

Browse files
committed
[BOJ] #2342.Dance Dance Revolution / ๊ณจ๋“œ3 / 90(X)
1 parent 59e3f16 commit 8b6ea14

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
steps = list(map(int, input().split()))
5+
if steps:
6+
steps.pop() # ๋งˆ์ง€๋ง‰ 0 ์ œ๊ฑฐ
7+
8+
# dp ํ…Œ์ด๋ธ”
9+
INF = float('inf') # ๋ฌดํ•œ๋Œ€ ๊ฐ’
10+
dp = [[INF]*5 for _ in range(5)]
11+
dp[0][0] = 0
12+
13+
def move_power(start, end):
14+
if start == 0: # ์ค‘์•™์—์„œ ๋‹ค๋ฅธ ๊ณณ์œผ๋กœ ์ด๋™ํ•˜๋Š” ๊ฒฝ์šฐ
15+
return 2
16+
if start == end: # ๊ฐ™์€ ์ง€์ ์„ ์—ฐ์†ํ•ด์„œ ๋ฐŸ๋Š” ๊ฒฝ์šฐ
17+
return 1
18+
if abs(start - end) == 2: # ๋ฐ˜๋Œ€ํŽธ์œผ๋กœ ์ด๋™ํ•˜๋Š” ๊ฒฝ์šฐ
19+
return 4
20+
return 3 # ์ธ์ ‘ํ•œ ์ง€์ ์œผ๋กœ ์ด๋™ํ•˜๋Š” ๊ฒฝ์šฐ
21+
22+
for step in steps:
23+
new_dp = [[INF]*5 for _ in range(5)] # ์ƒˆ๋กœ์šด dp ํ…Œ์ด๋ธ”
24+
25+
for left in range(5):
26+
for right in range(5):
27+
if dp[left][right] == INF:
28+
continue
29+
30+
current_power = dp[left][right] # ํ˜„์žฌ ์œ„์น˜์˜ ํž˜์˜ ์†Œ๋ชจ๋Ÿ‰
31+
32+
# ์™ผ๋ฐœ์„ ์›€์ง์ด๋Š” ๊ฒฝ์šฐ (์˜ค๋ฅธ๋ฐœ์ด step์— ์žˆ์œผ๋ฉด ์•ˆ ๋จ)
33+
if step != right:
34+
new_dp[step][right] = min(new_dp[step][right], current_power + move_power(left, step))
35+
36+
# ์˜ค๋ฅธ๋ฐœ์„ ์›€์ง์ด๋Š” ๊ฒฝ์šฐ (์™ผ๋ฐœ์ด step์— ์žˆ์œผ๋ฉด ์•ˆ ๋จ)
37+
if step != left:
38+
new_dp[left][step] = min(new_dp[left][step], current_power + move_power(right, step))
39+
40+
dp = new_dp # dp ํ…Œ์ด๋ธ” ์—…๋ฐ์ดํŠธ
41+
42+
print(min(min(row) for row in dp))

0 commit comments

Comments
ย (0)