当前位置:网站首页>leetcode2305. Fair distribution of biscuits (medium, weekly, shaped pressure DP)
leetcode2305. Fair distribution of biscuits (medium, weekly, shaped pressure DP)
2022-07-02 01:53:00 【Heavy garbage】



Train of thought : violence dfs, The time complexity is O(n^n), The time complexity is a little high .
Train of thought two : subset division + The number of subsets is limited -> Pressure dp Time complexity O(n * 3^n) Is constant
Pressure dp Related knowledge :
// Traverse u All nonempty subsets of
for (int s = u; s; s = (s - 1) & u) {
//s Express u A subset of u^s Means to remove s A subset of the latter
}
Specific ideas :
dp[i][j] Indicates that the number of sets consumed is i, The selected cookies are j The minimum value of the maximum total number of cookies obtained .
i The values for 1->k j The values for 1->(1<<n)
dp[i][j]=min(max(dp[i-1][j^s], sum[s]));
class Solution {
public:
int distributeCookies(vector<int>& cookies, int k) {
int n = cookies.size();
vector<int> sum(1 << n);
for (int i = 1; i < (1 << n); ++i) {
for (int j = 0; j < n; ++j) {
if (i & (1 << j)) sum[i] += cookies[j];
}
}
vector<vector<int>> dp(k, vector<int>(1 << n));
//dp[0] It means consumption 1 Group , The value obtained
dp[0] = sum;
for (int i = 1; i < k; ++i) {
for (int j = 1; j < (1 << n); ++j) {
dp[i][j] = INT_MAX;
for (int s = j; s; s = (s - 1) & j) {
dp[i][j] = min(dp[i][j], max(dp[i - 1][j ^ s], sum[s]));
}
}
}
return dp[k - 1][(1 << n) - 1];
}
};
边栏推荐
- 电子协会 C语言 1级 33 、奇偶数判断
- Niuke - Huawei question bank (51~60)
- TSINGSEE青犀平台如何实现同一节点同时播放多个视频?
- From January 11, 2007 to January 11, 2022, I have been in SAP Chengdu Research Institute for 15 years
- This is the report that leaders like! Learn dynamic visual charts, promotion and salary increase are indispensable
- Penser au jeu 15: penser au service complet et au sous - service
- 1218 square or round
- What are the skills of spot gold analysis?
- Data analysis on the disaster of Titanic
- matlab 使用 audiorecorder、recordblocking录制声音,play 播放声音,audiowrite 保存声音
猜你喜欢

Unity AssetBundle subcontracting

Word search applet design report based on cloud development +ppt+ project source code + demonstration video

matlab 使用 audiorecorder、recordblocking录制声音,play 播放声音,audiowrite 保存声音

Game thinking 15: thinking about the whole region and sub region Services

With the innovation and upgrading of development tools, Kunpeng promotes the "bamboo forest" growth of the computing industry

企业应该选择无服务器计算吗?

Redis环境搭建和使用的方法

Redis有序集合如何使用

【视频】马尔可夫链原理可视化解释与R语言区制转换MRS实例|数据分享

1222. Password dropping (interval DP, bracket matching)
随机推荐
分卷压缩,解压
Openssl3.0 learning XXI provider encoder
The concepts and differences between MySQL stored procedures and stored functions, as well as how to create them, the role of delimiter, the viewing, modification, deletion of stored procedures and fu
With the innovation and upgrading of development tools, Kunpeng promotes the "bamboo forest" growth of the computing industry
Implementation of Weibo system based on SSM
6-2 vulnerability exploitation - inevitable problems of FTP
开发工具创新升级,鲲鹏推进计算产业“竹林”式生长
[rust web rokcet Series 2] connect the database and add, delete, modify and check curd
医药管理系统(大一下C语言课设)
Matlab uses audioread and sound to read and play WAV files
734. Energy stone (greed, backpack)
自动浏览拼多多商品
There are spaces in the for loop variable in the shell -- IFS variable
Cross domain? Homology? Understand what is cross domain at once
Altium designer measure distance (ctrl+m)
Android: the kotlin language uses grendao3, a cross platform app development framework
Is the knowledge of University useless and outdated?
Number of palindromes in C language (leetcode)
Post infiltration flow encryption
基于SSM实现微博系统