当前位置:网站首页>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
边栏推荐
- hyperscan --- 1
- Global, exclusive and local routing guard
- PTA: 浪漫倒影 [二叉树重建] [深度优先遍历]
- Develop a chrome plug-in from 0 (2)
- 002_Redis_String类型常见的操作命令
- SQL server2019 cannot download the required files, which may indicate that the version of the installer is no longer supported. What should I do
- PTA: Romantic reflection [binary tree reconstruction] [depth first traversal]
- 002_ Redis_ Common operation commands of string type
- 双亲委派模型【理解】
- Yes, from today on, our fans can participate in Netease data analysis training camp for free!
猜你喜欢

每日一题(2022-04-22)——旋转函数
智能辅助功能丰富,思皓X6安全配置曝光:将于4月23日预售

arduino esp8266 网络升级 OTA

Talk about current limiting

每日一题(2022-04-21)——山羊拉丁文

The importance of ERP integration to the improvement of the company's system

Usage of vector common interface

009_ Redis_ Getting started with redistemplate

They are all intelligent in the whole house. What's the difference between aqara and homekit?

Target narak
随机推荐
Using go language to build web server
How to recognize products from the perspective of Dialectics
Talk about biology live broadcast: Dr. Wang Ziyuan, a lake view biology, exploring hepatitis B with gene therapy
day18--栈队列
下载正版Origin Pro 2022 教程 及 如何 激 活
After idea is successfully connected to H2 database, there are no sub files
How to prevent leakage of operation and maintenance data
【Chrome扩展程序】content_script的跨域问题
基于Torchserve部署SBERT模型<语义相似度任务>
Tp6 Alibaba cloud SMS window reports curl error 60: SSL certificate problem: unable to get local issuer certificate
RT_ Thread ask and answer
They are all intelligent in the whole house. What's the difference between aqara and homekit?
Global, exclusive, local Routing Guard
Common formatting problems after word writing
MySQL JDBC programming
Solve the problem that the registered Google email Gmail mobile number cannot be used for verification
PTA: 点赞狂魔
一个国产图像分割项目重磅开源!
[XJTU computer network security and management] Lecture 2 password technology
Rich intelligent auxiliary functions and exposure of Sihao X6 security configuration: it will be pre sold on April 23