2019年我能变强组队训练赛第二场(补题场) K Pakage 二维01背包
题目描述
It was bound to happen. Modernisation has reached the North Pole. Faced with escalating costs for feeding Santa Claus and the reindeer, and serious difficulties with security, NP Management has decided to do away with the traditional sleigh and adopt delivery by drone (magic, superfast drone).
Lack of investment capital means that the new system will start small, and hopefully grow in the years to come. For the first test run in 2017 there will be only two drones and they will have limited carrying capacity. PR is, of course, all important. There will be disappointment, and NP Management has decided to focus on delivering only the most expensive toys to the richest children, so as to focus the worst of the disappointment on those who have the greatest experience of coping (the poor).
Choosing the presents to deliver is your problem. You are being asked to develop an algorithm to select the cargo to deliver, given weight limits for each of the drones and a list of candidate presents with weights and values. Your goal is to maximise the value of gifts delivered.
输入
Input will consist of a series of problems. The first line of the input holds a single integer P being the number of problems. Then for each problem there will be three lines of input. The first line holds three integers: N (1 <= N <= 100) being the number of candidate presents; W1 and W2 (1 <= W1, W2 <= 1000) being the weight limits of the two drones respectively. The second line holds N integers (1 <= wi <= 100) being the weights of each of the candidate presents and the third line holds N integers (1 <= vi <= 100) being the values of the presents (in thousand dollar units). All lines are formatted with single spaces between numbers and no leading or trailing spaces.
输出
For each problem your program should output one line with the text “Problem “ and the number of the problem (counting from 1) followed by a colon, a space and the total value of presents shipped by the drone pair.
输入:
2 4 9 4 3 4 5 6 5 7 9 10 6 9 11 3 4 5 6 3 4 2 3 4 5 3 3
输出
Problem 1: 22
Problem 2: 16
题意:
两个无人机,其分别的载重量是W1、W2,然后有n个物品,其有一定的价值与重量,问最大的能够携带的物品价值是多少?
#include<iostream> #include<cstdio> #include<cstdlib> #include<algorithm> #include<string> #include<cmath> #include<cstring> #include<set> #include<queue> #include<stack> #include<map> #define rep(i,a,b) for(int i=a;i<=b;i++) typedef long long ll; using namespace std; const int N=1e5+10; const int INF=0x3f3f3f3f; int dp[1100][1100]; int w[400],val[400]; int main() { #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif // ONLINE_JUDGE int T; scanf("%d",&T); for(int o=1;o<=T;o++){ int n,M1,M2; scanf("%d%d%d",&n,&M1,&M2); memset(dp,0,sizeof dp); rep(i,1,n) scanf("%d",&w[i]); rep(i,1,n) scanf("%d",&val[i]); rep(i,1,n){ //分开写的话出现一些重复的数据,导致放了两遍 // for(int j=M1;j>=0;j--) // for(int k=M2;k>=w[i];k--){ // dp[j][k]=max(dp[j][k],dp[j][k-w[i]]+val[i]); // } // // for(int j=M1;j>=w[i];j--){ // for(int k=M2;k>=0;k--) // dp[j][k]=max(dp[j][k],dp[j-w[i]][k]+val[i]); // } for(int j=M1;j>=0;j--){ for(int k=M2;k>=0;k--){ if(j>=w[i]) dp[j][k]=max(dp[j][k],dp[j-w[i]][k]+val[i]); if(k>=w[i]) dp[j][k]=max(dp[j][k],dp[j][k-w[i]]+val[i]); } } } printf("Problem %d: ",o); printf("%d\n",dp[M1][M2]); } return 0; }
- 2017年暑假组队训练赛-No.2 F - 牧场物语 FZU - 2234
- bistuacm 2019年第四场新生训练赛题解
- 2013 - ECJTU 暑期训练赛第二场-problem-G
- 2017多校训练赛第二场 HDU 6053 TrickGCD(容斥原理/莫比乌斯反演)
- 2013 - ECJTU 暑期训练赛第二场-problem-H
- 训练赛第二场E题 Cottage Village
- 长沙理工组队赛 第二场 只A出来五道题目,银牌最后一名。。。伤不起!!!
- 2013 - ECJTU 暑期训练赛第二场-problem-J
- SDUT 2017 春夏组队训练赛3
- 2019年第十届蓝桥杯(c/c++)B组第1题 组队
- 2019年新生训练赛 第⑨场题解
- 2013暑假集训B组训练赛第二场
- 2013暑假集训B组训练赛第二场 - A Bus Game
- 2013暑假集训B组训练赛第二场 - E Queue at the School
- 训练赛第二场G题 ZOJ 2343
- 组队赛第二场:字符串哈希+DP
- Contest1255 - 2017区域赛组队训练赛10 K: keks
- 国庆训练赛第二场 模拟 能否一步还原二阶魔方
- bistuacm 2019年第⑧场新生训练赛题解
- hut 训练赛第二场 解题报告