当前位置:网站首页>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://blog.csdn.net/qq_27060423/article/details/124309993
边栏推荐
- New book recommendation - IPv6 technology and application (Ruijie version)
- Parental delegation model [understanding]
- Go语言web中间件的使用
- Fast and robust multi person 3D pose estimation from multiple views
- 每日一题(2022-04-21)——山羊拉丁文
- SQL server2019无法下载所需文件,这可能表示安装程序的版本不再受支持,怎么办了
- Open3d point cloud processing
- 【2019-CVPR-3D人体姿态估计】Fast and Robust Multi-Person 3D Pose Estimation from Multiple Views
- Synchronized lock and its expansion
- After idea is successfully connected to H2 database, there are no sub files
猜你喜欢

This is how the power circuit is designed

If 404 page is like this | daily anecdotes

都是做全屋智能的,Aqara和HomeKit到底有什么不同?

一个国产图像分割项目重磅开源!

Leetcode40 - total number of combinations II

006_redis_jedis快速入门

89 régression logistique prédiction de la réponse de l'utilisateur à l'image de l'utilisateur

Arduino esp8266 network upgrade OTA

How does Axure set the content of the text box to the current date when the page is loaded

Halo open source project learning (I): project launch
随机推荐
定了,今日起,本号粉丝可免费参与网易数据分析培训营!
Hyperscan -- 2 compilation
Lane cross domain problem
hyperscan --- 1
Gray scale range corresponding to colors (red, yellow, green, blue, purple, pink, brick red and magenta) in HSV color space
006_ redis_ Jedis quick start
Flink real-time data warehouse project - Design and implementation of DWS layer
IAR embedded development stm32f103c8t6 Lighting LED
day18--栈队列
[chrome extender] content_ Cross domain problem of script
Execute external SQL script in MySQL workbench and report error
假如404页面是这样的 | 每日趣闻
013_ Analysis of SMS verification code login process based on session
hack the box optimum靶机
Lighting LED of IAR embedded development stm32f103c8t6
Fast and robust multi person 3D pose estimation from multiple views
Multithreading technology core
全局、独享、局部路由守卫
想用Mac学习sql,主要给自己个充足理由买Mac听听意见
LeetCode 283. Move zero (simple, array) Day12