当前位置:网站首页>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];
}
};
边栏推荐
- I Brief introduction of radio energy transmission technology
- Implementation of Weibo system based on SSM
- Altium designer measure distance (ctrl+m)
- Matlab uses audiorecorder and recordblocking to record sound, play to play sound, and audiobook to save sound
- Unity AssetBundle subcontracting
- Post infiltration flow encryption
- 遷移雲計算工作負載的四個基本策略
- Construction and maintenance of business websites [11]
- Develop those things: how to use go singleton mode to ensure the security of high concurrency of streaming media?
- Ks006 student achievement management system based on SSM
猜你喜欢

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

卷積神經網絡(包含代碼與相應圖解)

Matlab uses resample to complete resampling

MySQL如何解决delete大量数据后空间不释放的问题

Using tabbar in wechat applet

Number of palindromes in C language (leetcode)

Six lessons to be learned for the successful implementation of edge coding

并发编程的三大核心问题

Pyldavis installation and use | attributeerror: module 'pyldavis' has no attribute' gensim '| visual results are exported as separate web pages

三分钟学会基础k线图知识
随机推荐
Laravel artisan common commands
JMeter (II) - install the custom thread groups plug-in
Self drawing of menu items and CListBox items
Implementation of Weibo system based on SSM
遊戲思考15:全區全服和分區分服的思考
Penser au jeu 15: penser au service complet et au sous - service
MySQL中一条SQL是怎么执行的
mysql列转行函数指的是什么
Matlab uses audioread and sound to read and play WAV files
Android: the kotlin language uses grendao3, a cross platform app development framework
Three core problems of concurrent programming
leetcode2311. 小于等于 K 的最长二进制子序列(中等,周赛)
What is AQS and its principle
Introduction to ffmpeg Lib
Electronic Association C language level 1 33, odd even number judgment
"C language programming", 4th Edition, edited by he Qinming and Yan Hui, after class exercise answers Chapter 3 branch structure Exercise 3
MySQL view concept, create view, view, modify view, delete view
Convolutional neural network (including code and corresponding diagram)
[rust web rokcet Series 2] connect the database and add, delete, modify and check curd
牛客网——华为题库(51~60)