当前位置:网站首页>Leetcode 879. profit plan
Leetcode 879. profit plan
2022-07-29 07:09:00 【HumbleFool】
LeetCode 879. Profit plan
Multidimensional 01 knapsack problem
const int N = 110, MOD = 1e9 + 7;
class Solution {
public:
int f[N][N][N] = {
0};// Before presentation i A job , The number of people does not exceed j, Profit does not exceed k Number of alternatives
int profitableSchemes(int m, int minProfit, vector<int>& g, vector<int>& p) {
int n = g.size();
for(int i = 0; i <= m; i ++) f[0][i][0] = 1; //0 A job , Profit is 0 It's a legal plan .
for(int i = 1; i <= n; i ++)
for(int j = 0; j <= m; j ++)
for(int k = 0; k <= minProfit; k ++)
{
f[i][j][k] = f[i - 1][j][k];
if(j >= g[i - 1])
f[i][j][k] =(0LL + f[i][j][k] + f[i - 1][j - g[i - 1]][max(0, k - p[i - 1])]) % MOD;
}
return f[n][m][minProfit];
}
};
Space optimization
const int N = 110, MOD = 1e9 + 7;
class Solution {
public:
int f[N][N] = {
0};// Before presentation i A job , The number of people does not exceed j, Profit does not exceed k Number of alternatives
int profitableSchemes(int m, int minProfit, vector<int>& g, vector<int>& p) {
int n = g.size();
for(int i = 0; i <= m; i ++) f[i][0] = 1;
for(int i = 1; i <= n; i ++)
for(int j = m; j >= 0; j --)
for(int k = minProfit; k >= 0; k --)
{
if(j >= g[i - 1])
f[j][k] =(0LL + f[j][k] + f[j - g[i - 1]][max(0, k - p[i - 1])]) % MOD;
}
return f[m][minProfit];
}
};
边栏推荐
- 线程 - 线程安全 - 线程优化
- 330. 按要求补齐数组
- Flink real-time warehouse DWD layer (processing complex data - installation and replacement of streams and tables) template code
- WPF嵌套布局案例
- leetcode-1331:数组序号转换
- 数组的子集不能累加出的最小正数
- 2022年SQL经典面试题总结(带解析)
- Teacher Wu Enda's machine learning course notes 02 univariate linear regression
- spark学习笔记(七)——sparkcore核心编程-RDD序列化/依赖关系/持久化/分区器/累加器/广播变量
- 模拟卷Leetcode【普通】061. 旋转链表
猜你喜欢
做开发4年13K,想转行自动化测试,薪资还能涨吗···
剑指 Offer II 115:重建序列
IO流 - File - properties
Teacher wangshuyao's operations research course notes 07 linear programming and simplex method (standard form, base, base solution, base feasible solution, feasible base)
二次元卡通渲染——进阶技巧
WPF简单登录页面的完成案例
Teacher wangshuyao's notes on operations research 04 fundamentals of linear algebra
buck电路boot和ph引脚实测
微信小程序的反编译
实现改变一段文字的部分颜色效果
随机推荐
Teacher wangshuyao's notes on operations research 05 linear programming and simplex method (concept, modeling, standard type)
Simulation volume leetcode [normal] 061. rotating linked list
基于C语言实现图书借阅管理系统
Junda technology | applicable to "riyueyuan" brand ups wechat cloud monitoring card
图像加噪声与矩阵求逆
剑指 Offer II 115:重建序列
Teacher wangshuyao's operations research course notes 07 linear programming and simplex method (standard form, base, base solution, base feasible solution, feasible base)
【charles日常问题】开启charles,使用不了钉钉
CVPR2021| 基于自监督学习的多视图立体匹配 (CVPR2021)
Relative date used by filter in salesforce
LeetCode 879. 盈利计划
vim文本编辑器的一些使用小技巧
Simulation volume leetcode [normal] 222. number of nodes of complete binary tree
游戏资产的革命
VMware16创建虚拟机:Win11无法安装
IO流 - File - properties
Federal learning backdoor attack summary (2019-2022)
Google fragmented notes JWT (Draft)
模拟卷Leetcode【普通】093. 复原 IP 地址
[solution] error: lib/bridge_ generated. dart:837:9: Error: The parameter ‘ptr‘ of the method ‘FlutterRustB