当前位置:网站首页>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
边栏推荐
- 解决 注册谷歌邮箱 gmail 手机号无法用于验证
- Handwritten memory pool and principle code analysis [C language]
- Program design: l1-49 ladder race, allocation of seats (simulation), Buxiang pill hot
- MySQL JDBC编程
- 012_ Access denied for user ‘root‘@‘localhost‘ (using password: YES)
- [XJTU computer network security and management] Lecture 2 password technology
- Usage of vector common interface
- 程序设计天梯赛 L1-49 天梯赛分配座位(模拟),布响丸辣
- 010_ StringRedisTemplate
- PTA: Romantic reflection [binary tree reconstruction] [depth first traversal]
猜你喜欢

Talk about current limiting

Arduino esp8266 network upgrade OTA

012_ Access denied for user ‘root‘@‘localhost‘ (using password: YES)

005_redis_set集合

day18--栈队列

002_ Redis_ Common operation commands of string type

MySQL C language connection

013_ Analysis of SMS verification code login process based on session

Talk about biology live broadcast: Dr. Wang Ziyuan, a lake view biology, exploring hepatitis B with gene therapy

小程序 canvas 画布半圆环
随机推荐
认识进程(多线程_初阶)
假如404页面是这样的 | 每日趣闻
Applet reads files
本地远程访问云服务器的jupyter
Talk about current limiting
每日一题冲刺大厂第十六天 NOIP普及组 三国游戏
16、 Anomaly detection
Deploying sbert model based on torchserve < semantic similarity task >
Execute external SQL script in MySQL workbench and report error
数仓建表111111
牛客手速月赛 48 C(差分都玩不明白了属于是)
C # import details
Network jitter tool clumsy
【Chrome扩展程序】content_script的跨域问题
013_ Analysis of SMS verification code login process based on session
Yes, from today on, our fans can participate in Netease data analysis training camp for free!
想体验HomeKit智能家居?不如来看看这款智能生态
Flink real-time data warehouse project - Design and implementation of DWS layer
Applet canvas canvas half ring
定了,今日起,本号粉丝可免费参与网易数据分析培训营!