To supplement my understanding of the Chinese test instructions.
You have to reassemble the computer. There are some parts of the computer.
Your budget has b,b (1~1E9), there are n parts.
Each part has type and name as well as price and quality
Now you have to be in the case of no more than budget B.
Buy one part for each type. Then the final quality is determined by the smallest quality
Under this constraint ask what is the maximum quality that you can assemble within budget b
Price range for each part 1e6, mass range 1e9
===============
Because money and quality are not necessarily linked
So we can not directly from the quality of small start greed.
Can not start from the high quality of greed it. Because you have to make sure you have enough money.
Sort by quality, money is disorderly. It's not good to handle anyway. Other processing methods I haven't thought of it yet.
So, what are you going to do about it?
A1,b1,a2,b2,a3,b3
C1,d1,c2,d2,c3,d3
X1,y1,x2,y2,x3,y3
Because once your money is fixed. For each enumerated total amount of money: The amount of money here is fixed.
That is, the amount of discrete money in DP. For each enumerated amount of money state: The money is fixed.
So you can't take the first one. will have an impact on the back. Because the total amount of money is less.
It's not too good. DP, if the remaining amount of the first I item is J can achieve the largest minimum quality
I later wanted to calculate the minimum amount of quality Q that can be achieved by the first I items. But because Q is very large can not be discrete. So you can't DP? The reason seems far-fetched.
I'm not too sure what the relationship is between Discretization and DP. But there's no question that DP can't solve some continuous problems.
One solution is to say: We have two final quality Q.
Before I was tangled
If the combination of the cheapest all parts is greater than or equal to Q1 exceeds the budget:
The cheapest combination of all parts that are greater than or equal to Q2 (Q2>Q1) does not exceed the budget
But it doesn't exist. Q monotonically increases when: The cheapest prices are also monotonically increasing.
Although the price is disorderly. But with the orderly nature of the quality of the monotonically increasing. Minimum price monotonically increasing.
I'm probably saying that. Because if the quality is small, it means that you are more selective (larger than the quality), so also the minimum price may be smaller, so we come to two minutes minimum quality. Because the cheapest parts are taken every time. So.. The total price is also monotonically increasing, the front has been proven. So the result for each of the two points: Take the cheapest part that is greater than or equal to this result for each part: The final check exceeds the budget by more than the quality left to go. No more than just go right. , the smallest budget that is greater than or equal to Q can be found, and the largest q that can be reached by the minimum budget, which is greater than or equal to Q, is achieved without exceeding the total budget.
My subscript is supposed to be 2. Since altogether 3 elements:
But.. Subscript 3,4 can be accessed. Do not report cross-border. Its value is a wild value bar.
We must pay attention to this point in the future.
But if you start your program, you access 4. It will stop running.
The trick of this vector must be well remembered.
#include <iostream>#include<cstdio>#include<map>#include<vector>#include<cstring>#include<algorithm>using namespacestd;intn,b,cnt;Charop1[ -];Charop2[ -];structnode{intX,q;node (intXintq): X (x), q (q) {}};typedefLong Longll;Const intmaxn=1e3+7; Vector<node>THINGS[MAXN];intMXCHEAP[MAXN][MAXN];BOOLCMP (node A,node b) {return(A.Q!=B.Q)?a.q<b.q:a.x<b.x;}voidInit () {intI for(i=0; i<maxn;++i) Things[i].clear ();}voidSort () {intI for(i=0; i<cnt;++i) sort (Things[i].begin (), Things[i].end (), CMP);}BOOLCheckintKey) {intI;ll sum=0; for(i=0; i<cnt;++i) { intleft=0, Right=things[i].size ()-1, Mid; while(left<=Right ) {Mid= (left+right) >>1; if(Things[i][mid].q<key) left=mid+1;Elseright=mid-1; } if(right+1<things[i].size () &&things[i][right+1].q>=key) right++; if(Left>things[i].size ()-1) { return false;} Sum+=Mxcheap[i][right]; } return(sum>b)?false:true;}intMain () {intT;SCANF ("%d",&t); while(t--) {scanf ("%d%d",&n,&b); init (); inti,j,x,q,lq=-1, rq=-1; cnt=0; Map<string,int>MP; for(i=0; i<n;++i) {scanf ("%s%s%d%d",op1,op2,&x,&q); if(!mp.count (string(OP1))) {mp[string(OP1)] =cnt++; } things[mp[string(OP1)]. Push_back (Node (x,q)); RQ= (rq==-1)?Q:max (Q,RQ); LQ= (lq==-1)?q:min (Q,LQ); } Sort (); for(i=0; i<cnt;++i) {mxcheap[i][things[i].size ()-1]=things[i].back (). x; for(J=things[i].size ()-2; j>=0;--j) {Mxcheap[i][j]=min (things[i][j].x,mxcheap[i][j+1]); } } intleft=lq,right=rq,mid,ans=-1; while(left<=Right ) {Mid= (left+right) >>1; if(Check (mid)) {left=mid+1;} Else{right=mid-1;} } if(Check (right+1)) right++; printf ("%d\n", right); } return 0;}
I made a mistake here. That's it. The two points in the check are wrong.
Even if it's right, it's not right. Because.. I thought the quality closest to Q is the cheapest price. It's just for everything that equals Q.
It may be cheaper to be more than Q. So here we need to preprocess the minimum value of the interval of i~size for each of the components.
Two points to get the boundary can be. But in terms of two points. We should consider both left>size-1 (size is the size of the vector)
Also consider left<0, such as the =q of the elements that require the first one. If all is greater than key, then right is less than 0,
You have to judge right+1 to avoid false negative, if all is less than key so right=size-1, and left=size, at this time left
We crossed the border. This is a complete no-solution. Be sure to pay attention to this point
Nature: The maximum value of the interval i~n of any unordered sequence is monotonous
hdu2333-greedy, how to go to aftereffect, backpack too big How to do, how to maximize the minimum value, from the disordered sequence to explore the ordered nature