算法记录
4.动态规划: i个物品,价格ai,收益bi,预算m,单次购买最大收益?
1 | def t1(): |
5.给定整数数组nums,给定元素个数n,求子数组?
解法1:常规遍历
1 | def subsets(nums): |
解法2: 位运算
1 | def subsets(nums): |
解法3: 回溯
1 | def subsets(nums): |
变种1: 求子数组和可被整除
解法1:拆分&查找
1 | print(sum(map(lambda x:x%m==0, subsets(nums)[1:]))) |