It looks very much like a backpack, but it's too bulky.
Knowledge of linear programming, enumeration of nearby points on the line, priority selection of cost-effective,
Treasures have two kinds of volume for S0, Value V0, Volume S1, Value V1.
The enumeration is divided into the following types:
1: Enumerate the number of Treasures 1, and then try to get more treasures 2;o (N/S0)
2: Enumerate the number of Treasures 2, ibid. O (N/S1)
3. Greedy, try to choose the cost-effective
Make gcd (s0,s1) = T,s1/t*s0 = S0/T*S1; the same volume as possible to choose high value, if s1*v0>s0*v1 large, then enumerate the number of Treasures 2, up to s0/t-1 or else must be replaced by s1/t 1 treasures. Vice versa. O (max{s0/t,s1/t})
The selection of the least enumerated amount can be determined in advance.
#include <bits/stdc++.h>using namespaceStd;typedefLong LongLl;ll GCD (ll a,ll b) {returnB? GCD (b,a%b): A;}intMain () {//freopen ("In.txt", "R", stdin); intT; ll s[2]; ll v[2]; ll N; scanf ("%d",&T); for(intCAS =1; CAS <= T; cas++) {scanf ("%lld%lld%lld%lld%lld", &n,s,v,s+1, v+1); BOOLFLAG0 = s[1]*v[0] > s[0]*v[1]; ll GCD= GCD (s[1],s[0]); ll T= (flag0?) s[0]/gcd:s[1]/GCD)-1; ll a[3] = {n/s[0],n/s[1],t}; ll Value=0; intFlag = Min_element (a,a+3)-A; intM =T; if(Flag <=1) { if(Flag = =1) {Swap (*s,s[1]); Swap (*v,v[1]); M = a[1];} ElseM = *A; }Else if(FLAG0) {Swap (*s,s[1]); Swap (*v,v[1]);} //enumerate the number of treasures 0 for(inti =0; I <= M; i++){ intj = (n-s[0]*i)/s[1]; ll Val= i*v[0] + j*v[1]; Value=Max (value,val); } printf ("Case #%d:%lld\n", Cas,value); } return 0;}
UVA 12325 Zombie ' streasurechest