当前位置:网站首页>LeetCode 879. 盈利计划
LeetCode 879. 盈利计划
2022-07-29 06:13:00 【HumbleFool】
LeetCode 879. 盈利计划
多维01背包问题
const int N = 110, MOD = 1e9 + 7;
class Solution {
public:
int f[N][N][N] = {
0};//表示前i个工作,人数不超过j,利润不超过k的方案数
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个工作,利润为0是一个合法方案。
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];
}
};
空间优化
const int N = 110, MOD = 1e9 + 7;
class Solution {
public:
int f[N][N] = {
0};//表示前i个工作,人数不超过j,利润不超过k的方案数
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];
}
};
边栏推荐
- Teacher wangshuyao's notes on operations research 06 linear programming and simplex method (geometric significance)
- 记 - 踩坑-实时数仓开发 - doris/pg/flink
- Thread synchronization - producers and consumers, tortoise and rabbit race, dual thread printing
- Flink实时仓库-DWD层(交易域-加购维度退化处理)模板代码
- resize2fs: 超级块中的幻数有错(Bad magic number in super-block )
- 说一下 TCP/IP 协议?以及每层的作用?
- 模拟卷Leetcode【普通】150. 逆波兰表达式求值
- Cesium反射
- pytest合集(7)— 参数化
- leetcode-592:分数加减运算
猜你喜欢

阿里一面,给了几条SQL,问需要执行几次树搜索操作?

JVM之垃圾回收机制(GC)

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

聊天机器人有何用处?有何类型?看完这些就明白了!

MVFuseNet:Improving End-to-End Object Detection and Motion Forecasting through Multi-View Fusion of

SSH password free login - two virtual machines establish password free channel two-way trust

实战!聊聊如何解决MySQL深分页问题

Junda technology | applicable to "riyueyuan" brand ups wechat cloud monitoring card

数组的子集不能累加出的最小正数

IO流 - File - properties
随机推荐
CVPR2022Oral专题系列(一):低光增强
MVFuseNet:Improving End-to-End Object Detection and Motion Forecasting through Multi-View Fusion of
Pytorch多GPU条件下DDP集群分布训练实现(简述-从无到有)
1172. 餐盘栈 有序列表+栈
Flink实时仓库-DWD层(交易域-加购维度退化处理)模板代码
pytest合集(7)— 参数化
Analog volume leetcode [normal] 093. Restore IP address
IO stream - file - properties
外包干了3年,跳槽后转自动化测试工资是原来的2倍,秘诀原来是......
Flink real-time warehouse DWD layer (Kafka associated with MySQL lookup join) template code
SSH免密登录-两台虚拟机建立免密通道 双向信任
实战!聊聊如何解决MySQL深分页问题
HJ37 统计每个月兔子的总数 斐波那契数列
Pod基本介绍
数组的子集能否累加出K
MVFuseNet:Improving End-to-End Object Detection and Motion Forecasting through Multi-View Fusion of
记 - 踩坑-实时数仓开发 - doris/pg/flink
Unity免费元素特效推荐
Teacher Cui Xueting's course notes on optimization theory and methods 00 are written in the front
图像加噪声与矩阵求逆