# unicorn eat ##### tags: `week 10` 窮舉法 ```python= n = int(input()) D = [list(map(int ,input().split())) for _ in range(n+1)] path = [] steps = D[0][n] for i in range(1 ,n+1):steps += D[i][i-1] temp = 0 f = open('result1.txt','a') def try_path(x ,p=[0]): global path ,steps ,temp for j in range(n+1): if j in p:continue temp += D[x][j] p.append(j) if len(p) == n+1: if temp < steps:path = p.copy() ;steps = temp if temp == steps and path > p:path = p.copy() p.pop() temp -= D[x][j] continue try_path(j ,p) p.pop() temp -= D[x][j] try_path(0) print(steps ,path ,sep='\n' ,file = f ,flush = True) ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up