原题链接
题目
输入
3
33 27
6 10
5 6
100 200
10 10
5 5
1 19
1 3
19 5
输出
11
20
3
Note
题意
你有一个容量为p的背包,你的随从有一个容量为f的背包,现在有cnts把重为s剑和cntw把重为w的斧,问你们最多能拿多少剑和斧。
思路
枚举可以装的剑和斧的最大数量,同时往自己和随从的背包里面装,最后取最大值。
代码:
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <cmath>
#include <map>
#include <list>
#include <set>
#include <cstdlib>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 55;
const int N = 10010;
const int INF = 0x3f3f3f3f;
const ll LNF = 0x3f3f3f3f3f3f3f3f;
const ll mod = 10007;
const double eps = 10e-6;
const double PI = 3.14159265358979323;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
priority_queue<int, vector<int>, less<int> >q;
priority_queue<int, vector<int>, greater<int> >qq;
int get(int cntss, int cntww, int ss, int ww, int ff){
if (ss > ww) return get(cntww, cntss, ww, ss, ff);
int buys = min (cntss, ff / ss);
int sum = buys;
ff -= buys * ss;
sum += min(cntww, ff / ww);
return sum;
}
int main(){
int t;
cin >> t;
while (t--){
int p, f, cnts, cntw, s, w;
cin >> p >> f >> cnts >> cntw >> s >> w;
int ans = 0, buy;
for (int i = 0; i <= cnts; i++){
if (i * s > p){
break;
}
buy = min (cntw, (p - i * s) / w);
ans = max (ans, i + buy + get (cnts - i, cntw - buy, s, w, f));
}
cout << ans << endl;
}
return 0;
}