-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path숫자 타자 대회.py
More file actions
25 lines (21 loc) · 938 Bytes
/
숫자 타자 대회.py
File metadata and controls
25 lines (21 loc) · 938 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
def solution(numbers):
def search(left, right, index, total):
if len(numbers) == index:
return total
if left == right:
return float('inf')
number = int(numbers[index])
left_total = search(number, right, index + 1, total) + weights[left][number]
right_total = search(left, number, index + 1, total) + weights[right][number]
return min(left_total, right_total)
weights = ((1, 7, 6, 7, 5, 4, 5, 3, 2, 3),
(7, 1, 2, 4, 2, 3, 5, 4, 5, 6),
(6, 2, 1, 2, 3, 2, 3, 5, 4, 5),
(7, 4, 2, 1, 5, 3, 2, 6, 5, 4),
(5, 2, 3, 5, 1, 2, 4, 2, 3, 5),
(4, 3, 2, 3, 2, 1, 2, 3, 2, 3),
(5, 5, 3, 2, 4, 2, 1, 5, 3, 2),
(3, 4, 5, 6, 2, 3, 5, 1, 2, 4),
(2, 5, 4, 5, 3, 2, 3, 2, 1, 2),
(3, 6, 5, 4, 5, 3, 2, 4, 2, 1))
return search(4, 6, 0, 0)