HDU 3496 Watch The Movie -- 二维费用背包 费用刚好完全消耗

/*
	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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值