当前位置:网站首页>Leetcode cooking
Leetcode cooking
2022-04-23 02:32:00 【I'm busy】
Welcome all brave people to Likou city , There are cooking pots in the city for the brave to make food , Recover for yourself .
The brave backpack has a total number of 0 ~ 4 Five ingredients , among materials[j] It means the first one j The number of ingredients . These ingredients can be used to make several dishes ,cookbooks[i][j] Means to make the first i This kind of food needs a second j The number of ingredients , and attribute[i] = [x,y] It means the first one i The delicacy of the dish x And satiety y.
The feeling of fullness is not less than limit Under the circumstances , Please return to the greatest delicacy available to the brave . If you can't meet the requirements of satiety , Then return to -1.
Be careful :
- Each dish can only be made once .
Example 1:
Input :
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 = 5Output :
7explain :
The quantity of ingredients can meet the following two schemes :
Scheme 1 : Make food 0 And cooking 1, You can get a sense of fullness 2+4、 Delicacy 3+2
Option two : Only cooking 2, But the feeling of fullness is 6、 The delicacy is 7
Therefore, in meeting the requirements of satiety , Get the highest taste 7
Example 2:
Input :
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 = 1Output :
11explain : By making food 0 and 1, It can satisfy the feeling of fullness , And get the highest taste 11
Tips :
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;
};
版权声明
本文为[I'm busy]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230231106858.html
边栏推荐
- 005_redis_set集合
- IAR嵌入式開發STM32f103c8t6之點亮LED燈
- 能做多大的单片机项目程序开发,就代表了你的敲代码的水平
- 005_ redis_ Set set
- 都是做全屋智能的,Aqara和HomeKit到底有什么不同?
- If you want to learn SQL with a Mac, you should give yourself a good reason to buy a Mac and listen to your opinions
- leetcode 烹饪料理
- Consider defining a bean of type ‘com.netflix.discovery.AbstractDiscoveryClientOptionalArgs‘
- Understanding process (multithreading primary)
- 001_ Redis set survival time
猜你喜欢
随机推荐
本地远程访问云服务器的jupyter
Go language ⌈ mutex and state coordination ⌋
012_ Access denied for user ‘root‘@‘localhost‘ (using password: YES)
How to prevent leakage of operation and maintenance data
使用Go语言构建Web服务器
A domestic image segmentation project is heavy and open source!
WordPress calls the specified page content. 2 get_ children()
Real math problems in 1958 college entrance examination
都是做全屋智能的,Aqara和HomeKit到底有什么不同?
001_ Redis set survival time
011_RedisTemplate操作Hash
RT_ Thread ask and answer
Lane cross domain problem
[XJTU computer network security and management] Lecture 2 password technology
[chrome extender] content_ Cross domain problem of script
PTA: 点赞狂魔
Kubernetes cluster installation based on Kirin SP10 server version
【无标题】
Hyperscan -- 2 compilation
Use of go language web Middleware




![Parental delegation model [understanding]](/img/ba/07e280a2634018e0d6b56c05dd3bc0.png)

![[untitled]](/img/60/421cda552055664357af47d1a956af.png)


