原题链接:
该题可以用DFS暴力筛出所有情况判断,但是python运行时间比较长,可能在三四分钟左右
ans = 0 # 答案
cnt = [False, True] # 答题情况
def dfs(k, score, choice): # 第k题,多少分,答题选择
global ans
if choice: #如果选对
score += 10
if score == 100: # 剪枝,到100分返回
return
else: # 选错
score = 0
if score == 70: # 70分,答案加一
ans += 1
if k == 31: return # 答完30题
for x in cnt: # 遍历情况
dfs(k + 1, score, x)
dfs(1, 0, False) # 从第一个开始,0分,错误和正确可以随便选
print(ans)