当前位置:网站首页>leetcode 烹飪料理
leetcode 烹飪料理
2022-04-23 02:31:00 【我很忙2010】
歡迎各比特勇者來到力扣城,城內設有烹飪鍋供勇者制作料理,為自己恢複狀態。
勇者背包內共有編號為 0 ~ 4 的五種食材,其中 materials[j] 錶示第 j 種食材的數量。通過這些食材可以制作若幹料理,cookbooks[i][j] 錶示制作第 i 種料理需要第 j 種食材的數量,而 attribute[i] = [x,y] 錶示第 i 道料理的美味度 x 和飽腹感 y。
在飽腹感不小於 limit 的情况下,請返回勇者可獲得的最大美味度。如果無法滿足飽腹感要求,則返回 -1。
注意:
- 每種料理只能制作一次。
示例 1:
輸入:
materials = [3,2,4,1,2]cookbooks = [[1,1,0,1,2],[2,1,4,0,0],[3,2,4,1,0]]attribute = [[3,2],[2,4],[7,6]]limit = 5輸出:
7解釋:
食材數量可以滿足以下兩種方案:
方案一:制作料理 0 和料理 1,可獲得飽腹感 2+4、美味度 3+2
方案二:僅制作料理 2, 可飽腹感為 6、美味度為 7
因此在滿足飽腹感的要求下,可獲得最高美味度 7
示例 2:
輸入:
materials = [10,10,10,10,10]cookbooks = [[1,1,1,1,1],[3,3,3,3,3],[10,10,10,10,10]]attribute = [[5,5],[6,6],[10,10]]limit = 1輸出:
11解釋:通過制作料理 0 和 1,可滿足飽腹感,並獲得最高美味度 11
提示:
materials.length == 51 <= cookbooks.length == attribute.length <= 8cookbooks[i].length == 5attribute[i].length == 20 <= materials[i], cookbooks[i][j], attribute[i][j] <= 201 <= limit <= 100
C++
class Solution {
public:
void dfs(vector<int>& materials, vector<vector<int>>& cookbooks, vector<vector<int>>& attribute, int k) {
if(k==cookbooks.size()) {
return;
}
for(int i=k;i<cookbooks.size();i++) {
satiety+=attribute[i][1];
yummy+=attribute[i][0];
int flag=0;
for(int j=0;j<5;j++) {
used[j]+=cookbooks[i][j];
if(used[j]>materials[j]) {
flag=1;
}
}
if (flag == 0) {
if (satiety >= limit) {
isFull=1;
res = max(res, yummy);
}
dfs(materials, cookbooks, attribute, i + 1);
}
for (int j = 0; j < 5; j++) {
used[j] -= cookbooks[i][j];
}
satiety-=attribute[i][1];
yummy-=attribute[i][0];
}
}
int perfectMenu(vector<int>& materials, vector<vector<int>>& cookbooks, vector<vector<int>>& attribute, int limit) {
used.resize(5);
this->limit=limit;
dfs(materials,cookbooks,attribute,0);
if(isFull==0) {
return -1;
}
return res;
}
private:
int satiety=0;
int yummy=0;
int isFull=0;
std::vector<int> used;
int limit;
int res=0;
};
版权声明
本文为[我很忙2010]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230231106858.html
边栏推荐
- IAR embedded development stm32f103c8t6 Lighting LED
- Program design: l1-49 ladder race, allocation of seats (simulation), Buxiang pill hot
- hyperscan --- 1
- 006_ redis_ Sortedset type
- Fast and robust multi person 3D pose estimation from multiple views
- RT_ Thread ask and answer
- 解决 注册谷歌邮箱 gmail 手机号无法用于验证
- The usage and difference of * and & in C language and the meaning of keywords static and volatile
- tp6阿裏雲短信 window 報 cURL error 60: SSL certificate problem: unable to get local issuer certificate
- [suggestion collection] hematemesis sorting out golang interview dry goods 21 questions - hanging interviewer-1
猜你喜欢

Deploying sbert model based on torchserve < semantic similarity task >

001_ Redis set survival time
![[untitled]](/img/60/421cda552055664357af47d1a956af.png)
[untitled]

手写内存池以及原理代码分析【C语言】

This is how the power circuit is designed
智能辅助功能丰富,思皓X6安全配置曝光:将于4月23日预售

假如404页面是这样的 | 每日趣闻

The 16th day of sprint to the big factory, noip popularization Group Three Kingdoms game

Halo open source project learning (I): project launch

001_redis设置存活时间
随机推荐
C # import details
013_基于Session实现短信验证码登录流程分析
PTA: praise the crazy devil
Wechat public platform test number application, authorized login function and single sign on using hbuilder X and wechat developer tools
[nk]牛客月赛48 D
1、 Sequence model
IAR嵌入式開發STM32f103c8t6之點亮LED燈
数仓建表111111
一、序列模型-sequence model
Global, exclusive, local Routing Guard
89 régression logistique prédiction de la réponse de l'utilisateur à l'image de l'utilisateur
Day18 -- stack queue
想体验HomeKit智能家居?不如来看看这款智能生态
SQL server2019无法下载所需文件,这可能表示安装程序的版本不再受支持,怎么办了
001_redis设置存活时间
002_Redis_String类型常见的操作命令
[assembly language] understand "stack" from the lowest point of view
JVM类加载器
Multithreading technology core
Download the genuine origin Pro 2022 tutorial and how to activate it