当前位置:网站首页>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 == 5
1 <= cookbooks.length == attribute.length <= 8
cookbooks[i].length == 5
attribute[i].length == 2
0 <= materials[i], cookbooks[i][j], attribute[i][j] <= 20
1 <= 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://blog.csdn.net/qq_27060423/article/details/124309993
边栏推荐
- Global, exclusive and local routing guard
- 010_StringRedisTemplate
- Real math problems in 1958 college entrance examination
- RT_ Thread ask and answer
- JVM类加载器
- Handwritten memory pool and principle code analysis [C language]
- Web learning record (medium)
- SO库依赖问题
- Dynamic batch processing and static batch processing of unity
- Startup of openstack service
猜你喜欢
小程序 canvas 画布半圆环
[XJTU計算機網絡安全與管理]第二講 密碼技術
002_ Redis_ Common operation commands of string type
A domestic image segmentation project is heavy and open source!
Talk about biology live broadcast: Dr. Wang Ziyuan, a lake view biology, exploring hepatitis B with gene therapy
高效音乐格式转换工具Music Converter Pro
Leetcode40 - total number of combinations II
Leetcode39 combined sum
SQL server2019 cannot download the required files, which may indicate that the version of the installer is no longer supported. What should I do
How does Axure set the content of the text box to the current date when the page is loaded
随机推荐
OJ daily practice - Finish
认识进程(多线程_初阶)
Web learning record (medium)
C # import details
Kubernetes cluster installation based on Kirin SP10 server version
After idea is successfully connected to H2 database, there are no sub files
Global, exclusive and local routing guard
Startup of openstack service
Real math problems in 1958 college entrance examination
定了,今日起,本号粉丝可免费参与网易数据分析培训营!
go语言打怪通关之 ⌈互斥锁和状态协程⌋
tp6阿裏雲短信 window 報 cURL error 60: SSL certificate problem: unable to get local issuer certificate
Synchronized lock and its expansion
十六、异常检测
Tp6 Alibaba Cloud SMS Window message Curl Error 60: SSL Certificate Problem: Unable to get local issuer Certificate
SO库依赖问题
Develop a chrome plug-in from 0 (2)
每日一题冲刺大厂第十六天 NOIP普及组 三国游戏
day18--栈队列
Numerical remapping method (remap)