Skip to content

Commit ba0128f

Browse files
committed
[BOJ] #2342. Dance Dance Revolution / 골드3 / 90분 / 실패
1 parent b4e1daa commit ba0128f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
nums = list(map(int, input().split()))
5+
6+
n = len(nums)
7+
dp = [[[4*len(nums) for _ in range(5)] for _ in range(5)]
8+
for _ in range(len(nums))]
9+
dp[0][0][0] = 0 # 초기값
10+
11+
12+
def move(start, end):
13+
if start == 0: # 0을 거침
14+
return 2
15+
if start == end: # 같은 지점
16+
return 1
17+
if abs(start - end) % 2 == 0: # 짝수차이가 나면 반대지점
18+
return 4
19+
else:
20+
return 3
21+
22+
23+
for i in range(n-1):
24+
start = nums[i]
25+
for left in range(5):
26+
for right in range(5):
27+
dp[i+1][left][start] = min(dp[i+1][left][start], dp[i][left][right] + move(right, start))
28+
dp[i+1][start][right] = min(dp[i+1][start][right], dp[i][left][right] + move(left, start))
29+
30+
print(min(map(min, dp[n-1])))

0 commit comments

Comments
 (0)