当前位置:网站首页>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];
}
};
边栏推荐
- SS command details
- Teacher wangshuyao wrote the notes of operations research course 00 in the front
- [C language brush leetcode] 1054. Bar code with equal distance (m)
- IO stream - file - properties
- Flink real time warehouse DWD layer (traffic domain) template code
- 如何优雅的写 Controller 层代码?
- Not so simple singleton mode
- DM数据守护集群搭建
- Leetcode-592: fraction addition and subtraction
- Flink实时仓库-DWD层(流量域)模板代码
猜你喜欢

CVPR2022Oral专题系列(一):低光增强

猜数字//第一次使用生成随机数

The core of openresty and cosocket

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

做开发4年13K,想转行自动化测试,薪资还能涨吗···

Improved Pillar with Fine-grained Feature for 3D Object Detection论文笔记

Jetpack Compose 中的键盘处理

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

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

2D cartoon rendering - advanced skills
随机推荐
Database multi table query joint query add delete modify query
MySQL: what happens in the bufferpool when you crud? Ten pictures can make it clear
DM data guard cluster setup
MySQL queries are case sensitive
Improved pillar with fine grained feature for 3D object detection paper notes
Flink real-time warehouse DWD layer (transaction domain - additional purchase dimension degradation processing) template code
Flink real-time warehouse DWD layer (order placing multiple tables to realize join operation) template code
上采样之反卷积操作
Is online legend software testing training really so black hearted? Are they all scams?
Flink real time warehouse DWD layer (traffic domain) template code
竣达技术 | 适用于”日月元”品牌UPS微信云监控卡
说一下 TCP/IP 协议?以及每层的作用?
Actual combat! Talk about how to solve the deep paging problem of MySQL
Google fragmented notes JWT (Draft)
没那么简单的单例模式
Unity免费元素特效推荐
CVPR2022Oral专题系列(一):低光增强
Salesforce中过滤器Filter使用的相对日期
解决CSDN因版权不明而无法发布博客的问题
Cvpr2022oral special series (I): low light enhancement