-
Notifications
You must be signed in to change notification settings - Fork 0
/
220817_양궁대회_L2.py
50 lines (46 loc) · 1.42 KB
/
220817_양궁대회_L2.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# backtracking, bfs, combination 모두 가능
# 모든 경우의 수를 다 해봐야 함
from copy import deepcopy
answer = [-1]
max_gap = 0
def back_tracking(n, info, arrow, idx):
global answer, max_gap
if sum(arrow) > n:
return
elif sum(arrow) == n:
apeach, lion = 0, 0
for i in range(11):
if info[i] == 0 and arrow[i] == 0:
continue
if info[i] >= arrow[i]:
apeach += (10-i)
else:
lion += (10-i)
if lion > apeach and lion - apeach > max_gap:
max_gap = lion - apeach
answer = deepcopy(arrow)
elif lion > apeach and lion - apeach == max_gap:
flag = False
for i in range(10, -1, -1):
if arrow[i] > answer[i]:
flag = True
break
if arrow[i] < answer[i]:
break
if flag:
max_gap = lion - apeach
answer = deepcopy(arrow)
return
if idx > 10:
return
if idx == 10:
arrow[idx] = n - sum(arrow)
else:
arrow[idx] = info[idx] + 1
back_tracking(n, info, arrow, idx+1)
arrow[idx] = 0
back_tracking(n, info, arrow, idx+1)
def solution(n, info):
global answer
back_tracking(n, info, [0 for i in range(11)], 0)
return answer