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))


#360公司##笔试题目#
全部评论
可以问一下题目是什么嘛
点赞 回复 分享
发布于 2019-08-31 19:34
两道题+起来不到三十行
点赞 回复 分享
发布于 2019-08-31 18:04

相关推荐

07-14 12:29
门头沟学院 Java
后端岗,实习三周感觉有点想跑路了,担心秋招被拉黑,有没有佬是字节HR知道情况的
从零开始的转码生活:你实习三周都想跑路,将来拿到offer真的愿意在这干十几二十年吗
投递字节跳动等公司8个岗位
点赞 评论 收藏
分享
05-27 14:57
西北大学 golang
强大的社畜在走神:27届真不用急,可以搞点项目、竞赛再沉淀沉淀,我大二的时候还在天天打游戏呢
投递华为等公司10个岗位
点赞 评论 收藏
分享
评论
1
6
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务