当前位置:网站首页>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
边栏推荐
- Go package import mode member visibility
- 间隔两个月,我的第二次上榜纪念日【2022.6.2】
- kali局域网ARP欺骗(arpspoof)并监听(mitmproxy)局域内其它主机上网记录
- Gospel of audio and video developers, rapid integration of AI dubbing capability
- 每日一博 - 微服务权限一二事
- Review of MySQL (VIII): Transactions
- Summary of interview questions
- Gospel of audio and video developers, rapid integration of AI dubbing capability
- Daily blog - micro service permission 12 matters
- 【sql语句基础】——查(select)(单表查询)
猜你喜欢

Common methods and examples of defect detection based on Halcon

MySQL - > > symbol usage JSON related

Review of MySQL (IX): index

MYSQL:Expression #4 of SELECT list is not in GROUP BY clause and contains nonaggregated column

How to download proxystrike in China

Go init initialization function

Gospel of audio and video developers, rapid integration of AI dubbing capability

Research Report on the overall scale, major manufacturers, major regions, products and application segmentation of swimming fins in the global market in 2022

吃饭咯 干锅肥肠 + 掌中宝!

kali通过iptables实现端口转发功能
随机推荐
CEPH deploy offline deployment of CEPH cluster and error reporting FAQ
Redis(三十二)-用Redis做分布式锁
Operational research optimization of meituan intelligent distribution system - Notes
收获满满的下午
标准库template学习入门原创
I was badly hurt by the eight part essay...
Gd32f4xx communicates with electric energy meter conforming to dlt645_ two
232-CH579M学习开发-以太网例程-TCP服务器(项目应用封装,局域网或广域网测试)
C language practice (4) -- multiplication and division of large numbers
Leetcode 474. 一和零
leetcode:6095. 强密码检验器 II【简单模拟 + 不符合直接False】
深圳3月14日起全市停工停业7天居家办公心得|社区征文
2022.6.12-----leetcode.890
liunx部署Seata(Nacos版)
Solution to the problem that the anaconda navigator card logo cannot be opened and the card will flash back - replace the alicloud image source
Experiment 10 Bezier curve generation - experiment improvement - control point generation of B-spline curve
The practice of machine learning in meituan distribution system: restoring the real world with technology - Notes
间隔两个月,我的第二次上榜纪念日【2022.6.2】
Leetcode 474. One and zero
Kali2022 how to install w3af