第一题太简单,不贴了。
但是这种秋招笔试,样例库的样例不多,笔试能过,不代表算法正确,欢迎网友提bug~
题目盗图
import sys
direc = [-1, 1]
line = sys.stdin.readline().strip()
n, m = list(map(int, line.split()))
num = 0
p, q = [], []
def judge(a):
if(a > 0 and a < n + 1):
return True
return False
def dfs(cur, id_):
if(id_ >= m):
if(cur <= n and cur > 0):
q.append(cur)
return
for k in range(2):
new = cur + p[id_] * direc[k]
if(judge(new) == True):
dfs(new, id_ + 1)
cur = new - p[id_] * direc[k]
return
for i in range(m):
p.append(int(sys.stdin.readline().strip()))
for st in range(1, n+1):
dfs(st, 0)
print(len(list(set(q))))