当前位置:网站首页>Cf:c. factors and powers of two [DP + sort + Select Board + select several numbers equal to the minimum number of known sums]
Cf:c. factors and powers of two [DP + sort + Select Board + select several numbers equal to the minimum number of known sums]
2022-07-07 17:49:00 【White speed Dragon King's review】
analysis
First construct the array , use set The deposit guarantee is unique
Then it becomes inverted list
then dfs,dfs Record current and , The remaining options , Number of selected
If the current sum is n success
prune : The remaining options are 0, The current sum is greater than n, The present and + The remaining optional sum is less than n
Then it returns the minimum value of the current first one with or without selection dfs
ac code
import sys
import functools
input = sys.stdin.readline
for _ in range(int(input())):
n = int(input())
s = set()
cnt = 1
now = 1
while cnt <= n:
s.add(cnt)
now += 1
cnt *= now
cnt = 1
while cnt <= n:
s.add(cnt)
cnt *= 2
lst = tuple(sorted(list(s), reverse = True))
def dfs(tempSum, tempLst, cnt):
# success
if tempSum == n:
return cnt
# fail 1
if len(tempLst) == 0 or tempSum > n:
return 0x7f7f7f7f
# cut branch, fail 2
if tempSum + sum(tempLst) < n:
return 0x7f7f7f7f
return min(dfs(tempSum + tempLst[0], tempLst[1:], cnt + 1), dfs(tempSum, tempLst[1:], cnt))
ans = dfs(0, lst, 0)
if ans < 0x7f7f7f7f:
print(ans)
else:
print(-1)
summary
Choose board or not
边栏推荐
- Ansible learning summary (9) -- ansible loop, condition judgment, trigger, processing failure and other task control use summary
- Target detection 1 -- actual operation of Yolo data annotation and script for converting XML to TXT file
- 【4500字归纳总结】一名软件测试工程师需要掌握的技能大全
- 企业经营12法的领悟
- Functions and usage of imageswitch
- <代码随想录二刷>链表
- LeetCode1051(C#)
- 【深度学习】3分钟入门
- 【TPM2.0原理及应用指南】 12、13、14章
- L1-025 正整数A+B(Lua)
猜你喜欢
漫画 | 宇宙第一 IDE 到底是谁?
本周小贴士#136:无序容器
第3章业务功能开发(安全退出)
Functions and usage of viewflipper
Ansible 学习总结(9)—— Ansible 循环、条件判断、触发器、处理失败等任务控制使用总结
机器人工程终身学习和工作计划-2022-
企业即时通讯软件是什么?它有哪些优势呢?
简单的loading动画
Ansible learning summary (9) -- ansible loop, condition judgment, trigger, processing failure and other task control use summary
Several best practices for managing VDI
随机推荐
【网络攻防原理与技术】第4章:网络扫描技术
【TPM2.0原理及应用指南】 1-3章
手机app外卖订餐个人中心页面
基于RGB图像阈值分割并利用滑动调节阈值
Dateticket and timeticket, functions and usage of date and time selectors
Functions and usage of viewswitch
Notification is the notification displayed in the status bar of the phone
Use onedns to perfectly solve the optimization problem of office network
Supplementary instructions to relevant rules of online competition
带动画的列表选中js特效
第2章搭建CRM项目开发环境(搭建开发环境)
Several best practices for managing VDI
L1-028 判断素数(Lua)
【网络攻防原理与技术】第7章:口令攻击技术 第8章:网络监听技术
yolo训练过程中批量导入requirments.txt中所需要的包
做软件测试 掌握哪些技术才能算作 “ 测试高手 ”?
阿富汗临时政府安全部队对极端组织“伊斯兰国”一处藏匿点展开军事行动
【重新理解通信模型】Reactor 模式在 Redis 和 Kafka 中的应用
[distributed theory] (I) distributed transactions
自动化测试:Robot FrameWork框架大家都想知道的实用技巧