Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 5006 Accepted Submission (s): 1032
Problem Description Some brave warriors come to a lost village. They is very lucky and find a lot of treasures and a big treasure chest, but with angry zombies.
The Warriors is so brave, they decide to defeat, the zombies and then bring all of the treasures back. A brutal long-drawn-out battle lasts from morning to night and the Warriors find the zombies is undead and invincible.
Of course, the treasures should not being left here. Unfortunately, the Warriors cannot carry all the treasures by the treasure chest to the due of the limitation of The chest. Indeed, there is only a types of Treasures:emerald and sapphire. All of the emeralds is equal in size and value, and with infinite quantities. So is sapphires.
Being the priest of the Warriors with the Magic Artifact:computer, and given the size of the chest, the value and size of Each types of gems, you should compute the maximum value of treasures we warriors could bring back.
Input There is multiple test cases. The number of test cases T (T <=) is given on the first line of the input file. For each test case, there was only one line containing five integers N, S1, V1, S2, V2, denoting the size of the treasure C Hest is N and the size and value of an emerald are S1 and V1, size and value of a sapphire is S2, V2. All integers is positive and fit in 32-bit signed integers.
Output a single line containing the case number and the maximum total value of all items The Warriors can carry with the chest.
Sample Input
2100 1 1 2 2100 34 34 5 3
Sample Output
Case #1:100Case #2:86
Source2011 Asia Shanghai Regional Contest
Known s S1 v1 s2 v2; x s1 and Y S2 are available, x*s1+y*s2<=s for Max (X*V1+Y*V2)
If the direct enumeration 0 to S/S1 can be fixed time-out so that the branch can be reduced, because the LCM (S1,S2) *k==x*s1+y*s2 always exist such a solution;
It is only possible to enumerate S%LCM (S1,S2), but be aware of the possibility of enumerating S%LCM (S1,S2) +LCM (S1,S2) Considering whether there is a loss
As for the hair to add a LCM, mainly the last one is less than the LCM space, this space with a LCM space combination, compared to two parts apart, consider,
There may be better results, then the hairs are not two lcm, this is metaphysics
In fact, when the 1+2 has been optimized, 1+2+1 the last part of a separate consideration on the line, because 1+2 optimal, must have been put down, and then +1 combination of consideration with
Separate consideration is the same, because it doesn't fit.
#include <map> #include <string> #include <cstring> #include <cstdio> #include <cstdlib># include<cmath> #include <queue> #include <vector> #include <iostream> #include <algorithm > #include <bitset> #include <climits> #include <list> #include <iomanip> #include <stack > #include <set>using namespace std;typedef long Long ll;ll gcd (ll one,ll) {return TWO==0?ONE:GCD (two,one%two );} ll LCM (ll One,ll) {return one*two/gcd (one,two);} int main () {int t;cin>>t;for (int cs=1;cs<=t;cs++) {ll c,hr,hb,wr,wb;cin>>c>>wr>>hr> >wb>>hb;ll X=LCM (WR,WB), ans,len;if (c<x) {ans=0;len=c;} Else{ans= (c/x-1) *max (X/WR*HR,X/WB*HB); len=c%x+x;} if (WR<WB) {swap (WR,WB); swap (HR,HB);} ll T1=0;for (ll i=0;wr*i<=len;i++) {ll t2=i*hr+ (LEN-I*WR)/wb*hb;t1=max (T1,T2);} cout<< "Case #" <<cs<< ":" <<ans+t1<<endl;}}
Hdu4901zombie ' s treasure Chest