当前位置:网站首页>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];
}
};
边栏推荐
- 20-40K| 梅卡曼德3D视觉算法/软件/产品经理招聘
- Simulation volume leetcode [normal] 061. rotating linked list
- 模拟卷Leetcode【普通】081. 搜索旋转排序数组 II
- 数组的子集不能累加出的最小正数
- [C language brush leetcode] 1054. Bar code with equal distance (m)
- Simulation volume leetcode [general] 150. evaluation of inverse Polish expression
- 基于C语言实现图书借阅管理系统
- Decompilation of wechat applet
- Kubernetes (五) ---------部署 Kubernetes Dashboard
- Security in quantum machine learning
猜你喜欢

Thread synchronization - producers and consumers, tortoise and rabbit race, dual thread printing

Guess the number / / generate a random number for the first time

Federal learning backdoor attack summary (2019-2022)

MutationObserver文档学习

H3C_利用设置缺省静态路由优先级实现出口双线路的主备功能

基于C语言实现图书借阅管理系统

解决CSDN因版权不明而无法发布博客的问题

buck电路boot和ph引脚实测

Teacher wangshuyao's operations research course notes 07 linear programming and simplex method (standard form, base, base solution, base feasible solution, feasible base)

Teacher wangshuyao's notes on operations research 04 fundamentals of linear algebra
随机推荐
Hj37 statistics of the total number of rabbits per month Fibonacci series
Some tips of vim text editor
线程 - 线程安全 - 线程优化
【C语言刷LeetCode】1054. 距离相等的条形码(M)
自定义事件
基于C语言设计的学生成绩排名系统
【Redis】Redis开发规范与注意事项
Windows 上 php 7.4 连接 oracle 配置
数组的子集能否累加出K
我的个人网站不让接入微信登录,于是我做了这个
SSH password free login - two virtual machines establish password free channel two-way trust
Flink实时仓库-DWD层(交易域-加购维度退化处理)模板代码
gin 模版
Teacher wangshuyao's notes on operations research 06 linear programming and simplex method (geometric significance)
模拟卷Leetcode【普通】081. 搜索旋转排序数组 II
Flink real-time warehouse DWD layer (transaction domain - additional purchase dimension degradation processing) template code
Pytorch多GPU条件下DDP集群分布训练实现(简述-从无到有)
我的创业邻居们
Leetcode-1331: array ordinal conversion
resize2fs: 超级块中的幻数有错(Bad magic number in super-block )