当前位置:网站首页>leetcode:5289. Distribute cookies fairly [see data range + DFS pruning]
leetcode:5289. Distribute cookies fairly [see data range + DFS pruning]
2022-06-12 18:43:00 【Review of the white speed Dragon King】


analysis
I didn't look at the data range at first Want to use sorting plus double pointers to try No idea at all
Then the data is so small that it can be violent
Namely dfs+ to flash back Try the current biscuits and give them to each child
Then, after the score, we can see that the maximum value among the children is the most unfair number
Then find a minimum value
Pay attention to pruning :
If the current maximum value is greater than the record minimum value, it can be cut off
ac code
class Solution:
def distributeCookies(self, cookies: List[int], k: int) -> int:
n = len(cookies)
#own = [0] * k
ans = inf
def dfs(now, own):
#print(now, own)
nonlocal ans
if now == n:
ans = min(ans, max(own))
return
if max(own) >= ans:
return
for i in range(k):
own[i] += cookies[now]
dfs(now + 1, own)
own[i] -= cookies[now]
dfs(0, [0] * k)
return ans
summary
dfs Without pruning, I ate a wave of overtime
Be careful dfs Is there any obvious pruning method after that
边栏推荐
- Solution to the problem that the anaconda navigator card logo cannot be opened and the card will flash back - replace the alicloud image source
- wireshark基本使用命令
- Observe the page of the website
- 基于Halcon的矩形卡片【手动绘制ROI】的自由测量
- Research Report on the overall scale, major manufacturers, major regions, products and applications of Electric Screwdrivers in the global market in 2022
- Leetcode topic [string]-541- reverse string II
- Title 37: sorting 10 numbers
- 每日一博 - 微服务权限一二事
- Summary of interview questions
- GD32F4xx控制DGUS 变量显示
猜你喜欢

Review of MySQL (VI): usage of Union and limit

leetcode:5259. 计算应缴税款总额【简单模拟 + 看看在哪个区间】

Pytest automated testing framework (II)

Go init initialization function

What is SAP support package stack

Title 37: sorting 10 numbers

论大型政策性银行贷后,如何数字化转型 ?-亿信华辰

To understand Devops, you must read these ten books!

kali局域网ARP欺骗(arpspoof)并监听(mitmproxy)局域内其它主机上网记录

kali2022如何安装w3af
随机推荐
VirtualLab basic experiment tutorial -6 Blazed grating
Extracting strings with grep awk
Review of MySQL (10): three paradigms of database
美团智能配送系统的运筹优化实战-笔记
Leetcode 474. 一和零
torch. New usage of where (old but ignored usage)
快速复制浏览器F12中的请求到Postman/或者生成相关语言的对应代码
The Bean Validation API is on the classpath but no implementation could be found
Review of MySQL (4): sorting operation
在思科模擬器Cisco Packet Tracer實現自反ACL
Review of MySQL (V): Joint table query and sub query
Research Report on the overall scale, major manufacturers, major regions, products and applications of Electric Screwdrivers in the global market in 2022
dumi 搭建文档型博客
【历史上的今天】6 月 12 日:美国进入数字化电视时代;Mozilla 的最初开发者出生;3Com 和美国机器人公司合并
kali局域网ARP欺骗(arpspoof)并监听(mitmproxy)局域内其它主机上网记录
OpenGL shadow implementation (hard shadow)
被八股文害惨了。。。
深圳3月14日起全市停工停业7天居家办公心得|社区征文
Quickly copy the request in browser F12 to postman/ or generate the corresponding code of the relevant language
Can tonghuashun open an account? Can tonghuashun directly open the security of securities companies on the app