当前位置:网站首页>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
边栏推荐
- 想用Mac学习sql,主要给自己个充足理由买Mac听听意见
- LeetCode 283. Move zero (simple, array) Day12
- Applet reads files
- Lane cross domain problem
- 类初始化和实例初始化面试题
- 006_ redis_ Jedis quick start
- SO库依赖问题
- Real math problems in 1958 college entrance examination
- Lighting LED of IAR embedded development stm32f103c8t6
- 009_ Redis_ Getting started with redistemplate
猜你喜欢

RT_Thread自问自答

Common formatting problems after word writing

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

Understanding process (multithreading primary)

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

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

小程序 canvas 画布半圆环
![Handwritten memory pool and principle code analysis [C language]](/img/9e/fdddaa628347355b9bcf9780779fa4.png)
Handwritten memory pool and principle code analysis [C language]

【无标题】

基于Torchserve部署SBERT模型<语义相似度任务>
随机推荐
wordpress 调用指定页面内容详解2 get_children()
So library dependency
Gray scale range corresponding to colors (red, yellow, green, blue, purple, pink, brick red and magenta) in HSV color space
WordPress calls the specified page content. 2 get_ children()
[XJTU计算机网络安全与管理]第二讲 密码技术
一个国产图像分割项目重磅开源!
每日一题(2022-04-21)——山羊拉丁文
[NK] Niuke monthly race 48 D
Applet reads files
PHP sorting of interview questions on April 20, 2022
tp6阿里云短信 window 报 cURL error 60: SSL certificate problem: unable to get local issuer certificate
Tp6 Alibaba Cloud SMS Window message Curl Error 60: SSL Certificate Problem: Unable to get local issuer Certificate
005_ redis_ Set set
005_redis_set集合
RT_ Thread ask and answer
Flink real-time data warehouse project - Design and implementation of DWS layer
小程序 canvas 画布半圆环
Use of go language web Middleware
Jupyter for local and remote access to ECS
[xjtu Computer Network Security and Management] session 2 Cryptographic Technology