practivceAlgorithm/swexpertacademy
[SWEA][Python] 1865 동철이의 일 분배
findTheValue
2021. 10. 7. 09:55
확률을 인자로 넘기는 백트래킹.
def dfs(row, p):
global max_p
if row == N:
max_p = p
return
for col in range(N):
next_p = p * P[row][col]
if not col_check[col] and next_p > max_p:
col_check[col] = True
dfs(row + 1, next_p)
col_check[col] = False
for test in range(1, int(input()) + 1):
N = int(input())
P = [list(map(lambda x: int(x) / 100, input().split())) for __ in range(N)]
col_check = [False] * N
max_p = 0
dfs(0, 1)
print(f'#{test} {max_p * 100:.6f}')