#44524: Python Solution with Dynamic Programming


mengchiehling@gmail.com (T S)

學校 : 不指定學校
編號 : 292622
來源 : [93.207.79.77]
最後登入時間 :
2024-12-15 21:48:28
a165. Magic number -- 愷愷 | From: [80.243.204.40] | 發表日期 : 2024-12-13 18:50

This is a solution somewhere between brutal force and dynamical programming, definitely not fully optimized but it worked.

 

You can define an iteration function with takes two inputs:

  1. the current number up to i digits
  2. the current step/depth

Then in the function, you check if the int(number) can divide the step completely.

If yes, you go through all the digits "123456789", pick one which is not within the current number, concatenate the current number and the selected digit, and send this new number and step + 1 into the next step.

Since the hint says that the outcome is unique. You can print it in step=9.

 
ZeroJudge Forum