360笔试
import math
from typing import List
class Solution:
def combinationSum2(self, candidates: List[int], target: int, people:int):
if sum(candidates) < target:
return []
candidates.sort()
jieguo = list()
res = list()
self.abc(jieguo, res, target,candidates, 0, people)
return jieguo, len(jieguo)
def abc(self,jieguo, res, target,candidates, index, people):
if sum(res) >= target and len(res) == people:
jieguo.append(res[:])
return
elif len(res) > people:
return
for i in range(index, len(candidates)):
res.append(candidates[i])
self.abc(jieguo, res, target,candidates, i+1, people)
res.pop()
a = Solution()
n = int(input())
for i in range(n):
m, target = map(int, input().split())
num = int(math.ceil(m/2))
can = list(map(int, input().split()))
print(a.combinationSum2(can, target, num))
from typing import List
class Solution:
def combinationSum2(self, candidates: List[int], target: int, people:int):
if sum(candidates) < target:
return []
candidates.sort()
jieguo = list()
res = list()
self.abc(jieguo, res, target,candidates, 0, people)
return jieguo, len(jieguo)
def abc(self,jieguo, res, target,candidates, index, people):
if sum(res) >= target and len(res) == people:
jieguo.append(res[:])
return
elif len(res) > people:
return
for i in range(index, len(candidates)):
res.append(candidates[i])
self.abc(jieguo, res, target,candidates, i+1, people)
res.pop()
a = Solution()
n = int(input())
for i in range(n):
m, target = map(int, input().split())
num = int(math.ceil(m/2))
can = list(map(int, input().split()))
print(a.combinationSum2(can, target, num))
全部评论
相关推荐
点赞 评论 收藏
分享
求offer的大角牛:你可以去****上投投看看,牛客大多数是it开发,技术支持,测试类的工作
点赞 评论 收藏
分享
05-29 13:37
北京科技大学 算法工程师 认真搞学习:28小登的建议,投算法岗不要写什么物理竞赛,互联网+,多写点项目,用什么算法做了什么。还有本科算法是不可能的
开发你这个也没有项目啊
点赞 评论 收藏
分享