//dp[i]表示挣i块钱最少需要的座位数
//01背包的思想,大家可以这样想,对于每个船我们可选可不选,那么这样
//很明显就是一个01背包了。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1e4+10;
const int INF = 0x3f3f3f3f;
int dp[maxn], n, m, k;
int cal(int x, int y){ //因此每个船的容量有限,因此我们需要特殊处理一下
int num = x/k + 1;
if(x+y <= num*k) return x+y; //上一条船正好还有没有放满的位置可以放
else return num*k+y; //另外找一条新船来放
}
int main(){
int T;
scanf("%d", &T);
while(T--){
scanf("%d%d%d", &n, &m, &k);
memset(dp, INF, sizeof(dp));
dp[0] = 0;
int a,b;
while(n--){
scanf("%d%d", &a, &b);
a++;
for(int i = 1e4; i >= b; i--)
if(dp[i-b] != INF) dp[i] = min(dp[i], cal(dp[i-b], a));
}
int ans = 1e4;
while(dp[ans] > k*m) ans--;
printf("%d\n", ans);
}
return 0;
}
HDU 3602 2012(2010 ACM-ICPC Multi-University Training Contest(16)——Host by NUDT)
最新推荐文章于 2021-08-15 20:06:13 发布
本文介绍了参与2010 ACM-ICPC多校训练赛(16)中由国防科技大学主办的HDU 3602题目,详细解析了题目的背景、要求和解决方案,为竞赛爱好者提供参考。
摘要由CSDN通过智能技术生成