πλ¬Έμ νμνκΈ°
- μ²μμλ μμ μΉΈμ λ§ 4κ°κ° μλ€.
- λ§μ κ²μνμ κ·Έλ €μ§ νμ΄νμ λ°©ν₯λλ‘λ§ μ΄λν μ μλ€.
- λ§μ΄ νλμ μΉΈμμ μ΄λμ μμνλ©΄ νλμ νμ΄νλ₯Ό νμΌνλ€.
- λ§μ΄ μ΄λνλ λμ€μ΄κ±°λ νλμμ΄ μλ μΉΈμμ μ΄λμ μμνλ©΄ λΉ¨κ°μ νμ΄νλ₯Ό νμΌ νλ€.
- λ§μ΄ λμ°© μΉΈμΌλ‘ μ΄λνλ©΄ μ£Όμ¬μμ λμ¨ μμ κ΄κ³ μμ΄ μ΄λμ λ§μΉλ€.
- κ²μμ 10κ°μ ν΄μΌλ‘, λ§€ ν΄λ§λ€ 1~5μ μ«μκ° κ° λ©΄μ νλμ© μ ν 5면체 μ£Όμ¬μλ₯Ό κ΅΄λ €μ λμ°© μΉΈμ μμ§ μμ λ§μ νλ κ³¨λΌ μ£Όμ¬μμ λμ¨ μλ§νΌ μ΄λμν¨λ€.
- λ§μ΄ μ΄λμ λ§μΉλ μΉΈμ λ€λ₯Έ λ§μ΄ μμΌλ©΄ κ·Έ λ§μ κ³ λ₯Ό μ μλ€.
- μ΄λμ λ§μΉλ μΉΈμ΄ λμ°© μΉΈμ΄λ©΄ κ³ λ₯Ό μ μλ€.
- λ§μ΄ μ΄λμ λ§μΉ λλ§λ€ μΉΈμ μ νμλ μκ° μ μμ μΆκ°λλ€.
- μ£Όμ¬μμμ λμ¬ μ 10κ°λ₯Ό 미리 μκ³ μμ λ, μ»μ μ μλ μ μμ μ΅λκ° κ΅¬νκΈ°
ν΄λΉ λ¬Έμ λ λ§€ ν΄λ§λ€ 4κ°μ λ§ κ°κ°μ μμ§μΌ μ μλ λͺ¨λ κ²½μ°μ μλ₯Ό μ°Ύμ λ§μ μμ§μ¬ κ°λ©΄μ μ»μ μ μλ μ μμ μ΅λκ°μ ꡬν΄μΌ νλ€. μ¦, λ°±νΈλνΉμ νμ©ν λΈλ£¨νΈν¬μ€ νμμ ν΅ν΄ λ΅μ ꡬν μ μλ€.
π μ½λ μ€κ³
- μ£Όμ¬μμμ λμ€λ μ«μ 10κ°λ₯Ό numbers 리μ€νΈμ μ λ ₯λ°λλ€.
- κ²μνμ μ 보λ₯Ό μ μ₯νκΈ° μν game_mapμ νλμ½λ©νλ€.
- λλ κ²μνμ κ° κ²½λ‘λ₯Ό "νΉμ μ§μ μμ μμν΄μ λ€λ₯Έ κ²½λ‘μ κ²ΉμΉ μ μλ μ§μ κΉμ§"λ‘ κ²½λ‘λ₯Ό λλ μ μ₯νλ€.
- 4κ°μ λ§ νμ¬ μμΉλ₯Ό μ μ₯ν current_positions 리μ€νΈμ μ»μ μ΅κ³ μ μλ₯Ό κΈ°λ‘ν high_score λ³μλ₯Ό μμ±νλ€.
- λ§μ μ΄λμμΌ°μ λ λ€λ₯Έ λ§κ³Ό μΆ©λνλμ§ μ¬λΆλ₯Ό κ²μ¬ν check_collisions(moving_token, way, count)λ₯Ό μ μνλ€.
- current_positionsλ₯Ό λλ©΄μ, νμ¬ νμΈ μ€μΈ λ§κ³Ό λ€λ₯Έ λ§μ΄ μλ‘ μμΉκ° λμΌνλ€λ©΄ Trueλ₯Ό 리ν΄νκ³ , μλλΌλ©΄ Falseλ₯Ό 리ν΄νλ€.
- λ°±νΈλνΉ μκ³ λ¦¬μ¦μ μνν ν¨μ backtracking(cur_round, score)λ₯Ό μ μνλ€.
- νμ¬ ν΄, μ¦ cur_roundκ° 10μ΄λ©΄ νμ¬κΉμ§μ μ μ scoreλ₯Ό κΈ°μ€μΌλ‘ high_score κ°±μ νκ³ ν¨μλ₯Ό μ’ λ£νλ€.
- νμ¬ μ£Όμ¬μ λμ΄ λͺμΈμ§ dice_numberμ μ μ₯νλ€.
- νμ¬ ν΄ κΈ°μ€ 4κ°μ λ§μ νλμ© μμ§μ΄λ©° λͺ¨λ κ²½μ°μ μλ₯Ό νμνλ€.
- κ° λ§μ μμΉ(way, count)(κ²½λ‘ λ²νΈ, ν΄λΉ κ²½λ‘μμ λͺλ²μ§Έ μΉΈμ μμΉνλμ§)μ μ£Όμ¬μμ λλ§νΌ μ΄λμμΌ game_mapμμ μ΄λμ μμΉν΄μΌ νλμ§λ₯Ό (new_way, new_count)λ‘ κ΅¬νλ€.
- κ³μ°λ new_way, new_countμ μμΉμ μ΄λ―Έ λ§μ΄ μ‘΄μ¬νλμ§ check_collisions(moving_token, new_way, new_count)λ₯Ό νΈμΆν΄ νμΈνλ€. μ΄λ―Έ μ‘΄μ¬νλ μμΉλΌλ©΄ λ€μ λ§λ‘ λμ΄κ°λ€.
- λ§μ μ΄λμν€κ³ current_positionsλ₯Ό κ°±μ ν backtracking(cur_round+1, score+μ΄λν μΉΈμ μ«μ)λ₯Ό μ¬κ·νΈμΆνλ€. κ·Έ ν current_positionsλ₯Ό 볡μνλ€.
- backtraking(0, 0)μ νΈμΆν΄ λͺ¨λ κ²½μ°μ λν νμμ μνν ν κ°±μ λ high_scoreλ₯Ό μΆλ ₯νλ€.
π μλ νμ°¨ μμ μ¬ν
game_map = [
[0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, -1],
[10, 13, 16, 19, 25, 30, 35, 40, -1],
[20, 22, 24, 25, 30, 35, 40, -1],
[30, 28, 27, 26, 25, 30, 35, 40, -1]
]
μμ κ°μ΄ κ²μνμ 0, 10, 20, 30μμ μΆλ°ν΄μ λμ°©μ§μ κΉμ§μ λ€κ°μ§ κ²½λ‘λ‘λ§ λλμ΄μ νλμ½λ© νλλ°, λκ°μ μΉΈμ λν μμ(ex. 10μμ μΆλ°ν΄μ 25 λμ°©νλ κ²κ³Ό 20μμ μΆλ°ν΄μ 25μ λμ°©νλ κ²μ λμΌν μΉΈμ λμ°©νλ κ²μ΄μ§λ§, μ game_mapμμλ λ€λ₯Έ μμμ)κ° μ¬λ¬ κ° μμ΄μ λ°©λ¬Έ μ²λ¦¬λ₯Ό μ΄λ ΅κ² λ§λ€μλ€. λ°©λ¬Έ μ²λ¦¬ λΆλΆμ μ¬λ¬λ² μμ νμμλ λΆκ΅¬νκ³ μλμ κ°μ νΉμ μΌμ΄μ€μμ κ³μ μ€λ΅μ΄ λμλ€.
2 2 2 2 2 2 2 2 2 2
κΈ°λκ°
166
κ·Έλμ νΉμ ν μΉΈμ λν ννμ νλλ§ κ°μ§ μ μλλ‘, μλμ κ°μ΄ game_mapμ μμ νκ³ μ½λ μμμ κ° κ²½λ‘μ λμ λλ¬ν κ²½μ° λ¬΄μ‘°κ±΄ λ€λ₯Έ κ²½λ‘λ‘ μ΄λμμΌ°λ€.
ex) 10μμ μΆλ°ν΄ 25λ₯Ό κ±°μ³κ°λ κ²½μ°μ 20μμ μΆλ°ν΄ 25λ₯Ό κ±°μ³κ°λ κ²½μ°, μ¦ game_map[1][4] λλ game_map[2][3]μ λλ¬νλ©΄ 무쑰건 game_map[4][0]μΌλ‘ μ΄λν΄μ μ§ν
game_map = [
[0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40],
[10, 13, 16, 19, 25],
[20, 22, 24, 25],
[30, 28, 27, 26, 25],
[25, 30, 35, 40],
[40, -1]
]
πμ λ΅ μ½λ
numbers = list(map(int, input().split()))
# κ²½λ‘λ³ μ μ
game_map = [
[0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40],
[10, 13, 16, 19, 25],
[20, 22, 24, 25],
[30, 28, 27, 26, 25],
[25, 30, 35, 40],
[40, -1]
]
current_positions = [[0,0] for _ in range(4)] # 4κ°μ λ§ κ°κ°μ μμΉ μ μ₯
high_score = 0
def backtracking(cur_round, score):
global high_score
if cur_round == 10:
high_score = max(high_score, score)
return
dice_number = numbers[cur_round]
visited_pos = []
for moving_token in range(4):
way, count = current_positions[moving_token]
# μ΄λ―Έ νμΈν μμΉμμ μμνλ €κ³ νλ©΄ μ€μ§
if [way, count] in visited_pos:
continue
visited_pos.append([way, count])
# μ΄λ―Έ λμ°©ν λ§μ λν μ²λ¦¬
if way == -1:
continue
new_way, new_count = move_token(way, count+dice_number)
if new_way == -1 and new_count == -1:
current_positions[moving_token] = [-1, -1]
backtracking(cur_round + 1, score)
current_positions[moving_token] = [way, count]
continue
current_score = game_map[new_way][new_count]
# νλμ μΉΈμμ μμνλ κ²½μ° κ²½λ‘ λ³κ²½
if new_way == 0 and current_score in [10, 20, 30]:
new_way = current_score // 10
new_count = 0
# λμ°©ν μΉΈμ λ€λ₯Έ λ§μ΄ μλμ§ νμΈ
if check_collision(moving_token, new_way, new_count):
continue
current_positions[moving_token] = [new_way, new_count]
backtracking(cur_round+1, score+current_score)
current_positions[moving_token] = [way, count]
def move_token(way, count):
while count >= len(game_map[way]) - 1:
if way == 5:
return -1, -1
count -= (len(game_map[way]) - 1)
way = 5 if way in [0, 4] else 4
return way, count
def check_collision(moving_token, new_way, new_count):
for idx, (way, count) in enumerate(current_positions):
if idx != moving_token and way == new_way and count == new_count:
return True
return False
backtracking(0, 0)
print(high_score)