阿里0814,算法岗第二题 咋做呀,想着暴力蹭点分,一点也没蹭上呀,怀疑又没理解题意。。。o(╥﹏╥)o
def dp(s,dicts):
# print(1111)
global count
cur = ''.join(s)
# print(cur)
if cur in dicts:
return
dicts.add(cur)
print(cur)
count = (count+1)%1000000007
# print(cur)
# print(count)
index = 0
while index<length-1:
pre = int(s[index])
last = int(s[index+1])
if pre>0 and last<9:
s[index] = str(pre-1)
s[index+1] = str(last+1)
# if ''.join(s) not in dicts:
dp(s,dicts)
s[index] = str(pre)
s[index + 1] = str(last)
if pre<9 and last>0:
s[index] = str(pre+1)
s[index+1] = str(last-1)
# if ''.join(s) not in dicts:
dp(s,dicts)
s[index] = str(pre)
s[index + 1] = str(last)
index+=1
q = int(input())
for i in range(q):
s = [each for each in input()]
if len(s)<2:
print(0)
continue
count = -1
length = len(s)
dicts = set()
dp(s,dicts)
print(count)
#笔试题目##阿里巴巴#