题目
题目链接:http://poj.org/problem?id=2392
题目来源:《挑战》练习题
简要题意: K 种块,每种高度
hi 有 ci 个,顶部位置不能超过 ai 求搭起来的最大高度。数据范围: 1⩽K⩽400;1⩽hi⩽100;1⩽ci⩽10;1⩽ai⩽40000
题解
实际上肯定是个多重背包咯。
对 ai 排序然后每轮以 ai 为容量去做多重背包就行了。
由于只要判断访问,可以使用一些poj 1742 题解这里面的优化技巧
实现
用普通的多重背包估计也是可以的,我没试过。
代码
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <set>
#include <map>
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
LL powmod(LL a,LL b, LL MOD) {LL res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
// head
const int N = 405;
const int M = 4E4+5;
struct Node {
int lim, cnt, v;
bool operator<(const Node &o) const {
return lim < o.lim;
}
};
Node a[N];
bool dp[M];
int cnt[M];
int use[M];
int main()
{
int n, from;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d%d%d", &a[i].v, &a[i].lim, &a[i].cnt);
}
sort(a+1, a+n+1);
dp[0] = true;
for (int i = 1; i <= n; i++) {
for (int j = a[i].v; j <= a[i].lim; j++) {
from = j-a[i].v;
if (dp[from] && !dp[j] && (use[from] != i || cnt[from] < a[i].cnt)) {
dp[j] = true;
cnt[j] = use[from] == i ? cnt[from]+1 : 1;
use[j] = i;
}
}
}
for (int i = a[n].lim; ~i; i--) {
if (dp[i]) {
printf("%d\n", i);
break;
}
}
return 0;
}