当前位置:网站首页>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];
}
};
边栏推荐
- CVPR2022Oral专题系列(一):低光增强
- [CF1054H] Epic Convolution——数论,卷积,任意模数NTT
- Teacher wangshuyao's operations research course notes 07 linear programming and simplex method (standard form, base, base solution, base feasible solution, feasible base)
- gin 模版
- 约瑟夫环问题
- 要不要满足客户所有的需求
- 基于C语言设计的学籍管理系统
- win11系统错误:由于找不到 iertutil.dll,无法继续执行代码。重新安装程序可能会解决此问题
- Overview of database system
- SSH password free login - two virtual machines establish password free channel two-way trust
猜你喜欢
随机推荐
Flink real-time warehouse DWD layer (processing complex data - installation and replacement of streams and tables) template code
基于C语言实现图书借阅管理系统
Simulation volume leetcode [normal] 061. rotating linked list
外包干了3年,跳槽后转自动化测试工资是原来的2倍,秘诀原来是......
实现改变一段文字的部分颜色效果
Can MySQL export tables regularly?
Record - step on the pit - real-time data warehouse development - doris/pg/flink
Google fragmented notes JWT (Draft)
VMware16创建虚拟机:无法创建新虚拟机,不具备执行此操作的权限
Relative date used by filter in salesforce
pytest合集(7)— 参数化
太空射击第17课: Game Over (結束)
Cesium反射
Implementation of DDP cluster distributed training under pytoch multi GPU conditions (brief introduction - from scratch)
Salesforce中过滤器Filter使用的相对日期
模拟卷Leetcode【普通】061. 旋转链表
mysql查询区分大小写
dba
Teacher Cui Xueting's course notes on optimization theory and methods 00 are written in the front
Unity exploration plot access design analysis & process + code specific implementation








