当前位置:网站首页>Cuisine leetcode
Cuisine leetcode
2022-04-23 02:31:00 【Je suis occupé 2010】
Bienvenue à tous les braves dans la ville de leishu,Il y a des casseroles de cuisine dans la ville pour les braves,Pour se remettre en forme.
Il y a des numéros dans le sac à dos des braves 0 ~ 4 Cinq ingrédients,Parmi eux materials[j] Indique le paragraphe j Quantité de matériel végétal.Plusieurs plats peuvent être préparés à partir de ces ingrédients,cookbooks[i][j] Représente la production d'un i Pour la culture, il faut j Quantité de matériel végétal,Et attribute[i] = [x,y] Indique le paragraphe i La délicatesse de la cuisine x Et la satiété y.
Pas moins de limit Dans le cas de,S'il vous plaît revenir à la plus grande délicatesse disponible pour les braves.Si les besoins de satiété ne peuvent être satisfaits,Renvoie -1.
Attention!:
- Chaque préparation ne peut être faite qu'une seule fois.
Exemple 1:
Entrée:
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 = 5Produits:
7Explication:
La quantité d'ingrédients peut répondre aux deux options suivantes:
Programme I:Faire la cuisine 0 Et la cuisine 1,Pour obtenir une sensation de satiété 2+4、Delicious Degree 3+2
Programme II:Faire uniquement la cuisine 2, Peut se sentir plein pour 6、Le goût est 7
Donc, à la satisfaction de la satiété,Obtenez la plus grande délicatesse possible 7
Exemple 2:
Entrée:
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 = 1Produits:
11Explication: Par la fabrication de la nourriture 0 Et 1, Satiété suffisante , Et obtenir la plus grande délicatesse 11
Conseils:
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;
};
版权声明
本文为[Je suis occupé 2010]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230231106858.html
边栏推荐
- Data warehouse construction table 111111
- PHP sorting of interview questions on April 20, 2022
- 智能辅助功能丰富,思皓X6安全配置曝光:将于4月23日预售
- IAR嵌入式開發STM32f103c8t6之點亮LED燈
- 都是做全屋智能的,Aqara和HomeKit到底有什么不同?
- Applet reads files
- 【2019-CVPR-3D人体姿态估计】Fast and Robust Multi-Person 3D Pose Estimation from Multiple Views
- 手写内存池以及原理代码分析【C语言】
- Understanding process (multithreading primary)
- Usage of vector common interface
猜你喜欢

Network jitter tool clumsy

011_ Redistemplate operation hash

Deploying sbert model based on torchserve < semantic similarity task >

Hack the box optimum

SQL server2019 cannot download the required files, which may indicate that the version of the installer is no longer supported. What should I do

Wechat public platform test number application, authorized login function and single sign on using hbuilder X and wechat developer tools

How many steps are there from open source enthusiasts to Apache directors?

Yes, from today on, our fans can participate in Netease data analysis training camp for free!

Open3d point cloud processing

假如404页面是这样的 | 每日趣闻
随机推荐
Global, exclusive, local Routing Guard
How to recognize products from the perspective of Dialectics
JVM类加载器
hyperscan --- 1
双亲委派模型【理解】
Understanding process (multithreading primary)
C standard library - < time h>
If 404 page is like this | daily anecdotes
009_ Redis_ Getting started with redistemplate
Target narak
Solve the problem that the registered Google email Gmail mobile number cannot be used for verification
【无标题】
Go language ⌈ mutex and state coordination ⌋
Real math problems in 1958 college entrance examination
89 logistic regression user portrait user response prediction
Consider defining a bean of type 'com netflix. discovery. AbstractDiscoveryClientOptionalArgs‘
How many steps are there from open source enthusiasts to Apache directors?
Arduino esp8266 network upgrade OTA
R language advanced | generalized vector and attribute analysis
[XJTU計算機網絡安全與管理]第二講 密碼技術