【题目来源】AcWing 8. 二维费用的背包问题
【题意分析】
本题在前面背包问题的基础上,增加了一个维度——质量,背包拥有了容积、承重两个限制,物品也有了体积、质量两种属性。
【参考资料】第一讲 0/1背包问题
与0/1背包类似,加入一层循环限制重量即可:
#include<iostream>
using namespace std;
const int N1 = 1050;
const int N2 = 110;
struct node{
int v, m, w;
} q[N1];
int n, V, M;
int dp[N1][N2][N2];
//1000 * 100 * 100 = 107,1000ms能过