/*
http://acm.hdu.edu.cn/showproblem.php?pid=3496 Watch The Movie
二维费用的背包 其中第二费用为隐藏条件
恰好第二费用刚好完全消耗,注意初始化。别太粗心了
*/
#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
#define CLR(c,v) (memset(c,v,sizeof(c)))
using namespace std;
const int inf = -(1<<30);
const int INF = (1<<30);
const int M = 1e3 + 10;
int dp[M][110]; // 二维费用背包
int v[M];
int c[M];
void ZeroOnePack(int cost,int cost2, int value, int max_cost, int max_cost2){
for(int j = max_cost2 ; j >= cost2 ; j--){
for (int i = max_cost ; i >= cost ; i--){
if( dp[i][j] < dp[i-cost][j-cost2] + value){
dp[i][j] = dp[i-cost][j-cost2] + value;
}
}
}
}
int main (){
int Ncase;
cin >> Ncase;
while(Ncase --){
int n,max_cost2,max_cost;
cin >> n >> max_cost2 >> max_cost;
for(int i = 0 ; i <= max_cost ; i++){
for(int j = 0 ; j <= max_cost2 ; j++){
dp[i][j] = inf;
}
dp[i][0] = 0; // 注意初始化
}
for (int i = 1 ; i <= n ; i++){
cin >> c[i] >> v[i] ;
ZeroOnePack(c[i] , 1 , v[i] , max_cost , max_cost2);
}
if (dp[max_cost][max_cost2] < 0)
dp[max_cost][max_cost2] = 0; //If DuoDuo can’t watch all of the movies that her uncle had bought for her, please output 0.
cout << dp[max_cost][max_cost2] << endl;
}
return 0;
}
HDU 3496 Watch The Movie -- 二维费用背包 费用刚好完全消耗
最新推荐文章于 2019-05-31 19:15:53 发布