藍(lán)橋杯pythonB組題目思路(評(píng)價(jià)

哥 E題這么寫的,條件都沒想全,實(shí)在是受不了了[大哭]
import functools
n = int(input())
s1 = list(map(int, input()))
s2 = list(map(int, input()))
@functools.lru_cache(10000000000000)
def dfs(i, j):
if i < 0:
return 0
if j == s2[i]:
return dfs(i-1, s1[i-1])
if j > s2[i]:
return min(dfs(i-1, s1[i-1])+j-s2[i], dfs(i-1, s1[i-1]+1)+s2[i]+10-j)
else:
return min(dfs(i-1, s1[i-1])+s2[i]-j, dfs(i-1, s1[i-1]-1)+j+10-s2[i])
print(dfs(n-1, s1[n-1]))
標(biāo)簽: