"Problem description"
The backpack is a good thing, I hope I have it.
Give you a two-dimensional backpack, its volume is? X?. Now you have some size for 1x2 and 1x
3 of the items, each item has its own value. You want to put some items in your backpack so that they
Value and maximum, ask the maximum value and is how much.
"Input Format"
The first line an integer? The number of data groups that represent the test point.
For each set of data, the first row has four integers?,?,? 1,? 2, where? 1,? 2 represents the size of each
The number of items in 1x2 and size 1x3.
1x2 Next line has? 2 numbers represent the value of each 1x3 item.
"Output Format"
For each set of queries, the output can reach the maximum value.
"Sample Input"
1
2 3 2 2
1 2
1 2
"Sample Output"
4
"Sample Interpretation"
There is a mountain in the temple, in fact it is Zhong.
"Data size and conventions"
2,? 1,? 2≤100.
70% of data,?,? ≤100, huh? 1,? 2≤2000.
For 100% of data, 1≤? ≤10,1≤?,? ≤500,0≤? 1,? 2≤10000.
Ideas:
This is disgusting, I'll tell you.
When doing this the first reflection is DP, then Fengfenghuohuo to play two-dimensional backpack template
After playing back a look at the silly eye (this tells us to read the question carefully)
It was later known that the title was a prefix and a + enumeration
That
How do you enumerate it?
This enumeration
Determine how many items with a volume of 3 can be placed
And then cycle from 0 to max3.
Each cycle uses the total volume minus the overall product volume of the item that has been lowered by 3
And record the biggest ans.
Well
This is a 20-point approach
That
What about the way out?
And a little judgment on the way out.
Now let's think about all the objects that can't be split or bent.
So the length of the object must have sufficient space length
But
If the length of the backpack ==2 or the width of the backpack ==2
At this point, items of length 3 can be placed vertically or horizontally.
If the backpack width is 2 and the length is a multiple of 3 (including 0) +2
The maximum number of objects that can be lowered at this time is 3 (n*m-4)/3
So
If a backpack is fulfilled ((m==2| | n==2) &&m%3==2&&n%3==2)
The
The number of items that can be lowered by a volume of 3 is (N*M-4)/3
Speaking of which, the basic AC is available.
But
Don't rush to write code.
And there's a very important condition.
Is the total number of items that cannot exceed the volume of 3
Or the total number of items with a volume of 2
Come on, on the code:
#include <cstdio>#include<cstring>#include<algorithm>using namespacestd;intt,sum2[10001],sum3[10001],n,m,n2,n3;intmin2,min3,max2,max3,sq,ans=0, KCC;Charch;voidQread (int&x) {x=0; ch=GetChar (); while(ch>'9'|| ch<'0') ch=GetChar (); while(ch<='9'&&ch>='0') {x=x*Ten+(int) (ch-'0'); ch=GetChar ();}}BOOLcmpintAintb) {returnA>b;}intMain () {qread (T); while(t--) {ans=0, min2=0, min3=0; Qread (n), Qread (M), Qread (N2), Qread (N3); for(intI=1; i<=n2;i++) Qread (Sum2[i]); for(intI=1; i<=n3;i++) Qread (Sum3[i]); Sort (sum2+1, sum2+n2+1, CMP); Sort (sum3+1, sum3+n3+1, CMP); for(intI=1; i<=n2;i++) sum2[i]+=sum2[i-1]; for(intI=1; i<=n3;i++) sum3[i]+=sum3[i-1]; Sq=n*m; if((n%3==2&&m%3==2) && (n==2|| m==2)) max3= (sq-4)/3; Elsemax3=sq/3; intKol=0; Max3=min (max3,n3); for(inti=min3;i<=max3;i++) {Kol=0; Kol+=Sum3[i]; KCC= (sq-(i*3))/2; KCC=min (N2,KCC); Kol+=SUM2[KCC]; Ans=Max (Ans,kol); } printf ("%d\n", ans); } return 0;}
Two-dimensional backpack (Zhong wanted) (not DP)