360 散步
想了半小时, 最后没办法了, 暴力搜索,竟然过了, wdnmd
''' @Author: rayenwang @Date: 2019-08-31 17:45:00 @Description: ''' class Solution: def __init__(self, length): self.length = length self.end = set() def dfs(self, step, index, position): if position > self.length or position < 1: return if index == len(step): self.end.add(position) return self.dfs(step, index + 1, position + step[index]) self.dfs(step, index + 1, position - step[index]) N, M = [int(n) for n in input().split()] step = [] for _ in range(M): step.append(int(input())) result = set() for i in range(1, N + 1): s = Solution(N) s.dfs(step, 0, i) result = result | s.end print(len(result))