Solid foundation --P2705 ball

Topic links: https://www.luogu.org/problem/P2705

P2705 ball

Title Description

With R red box and blue box B, there is a red globules R and blue B pellets. Each box can only put a small ball, each ball should be placed in a box.

If a red ball in a red box, then the score is C. If you put a little blue ball in a blue box, then the score is D. If a red ball in a blue box, then the score is E. If you put a little blue ball in a red box, then the score is E.

Now given R, B, C, D, E. How should place these balls into the box, in order to make maximum total score? The maximum output of the total score.

Input Format

Line, five integers, respectively, R, B, C, D, E.

Output Format

An integer, maximum total score.

Sample input and output

Input # 1
2 3 100 400 200
Output # 1
1400
Input # 2
2 3 100 400 300
Output # 2
1600

Description / Tips

[Data] scale

1 ≤ R ≤ 100,1 ≤ B ≤ 100, -1000 ≤ C,D,E ≤ 1000。

 

This question is a simple number of topics, in fact, really want to listen to the law, since the same red ball and blue ball into a different box score, then you can see them as a whole, more "into a different box of the remaining scores + score balls into the size of the value of their own box, "and" all put in their own box score value ". And that must be the right solution.

If you do not believe, here we have to prove by contradiction follows:

Assuming: the above solution is not optimum, then there must be a case that the value is larger than the above two cases, and the balls can not completely basketball and red and the other into a respective box. So if you want to meet these circumstances, with the proviso that " c + d> E + E ", then we can discuss the next step.

Since basketball and red balls can not be completely put in the other box, then there is necessarily a case of:

" Min (r, b) * e * 2> N * e * 2 (N <min (r, b)) ",

Since then the situation is hypothetical optimal solution, so

" Min (R & lt, B) * E * 2 + (max (R & lt, B) - min (R & lt, B)) * m <N * E * 2 + R & lt * C + B * D (N <min (R & lt, b), R, B and the remaining red ball basketball, m is the ball into their own column value C / D)  ",

Then we can introduce further

' K * e * 2 + (max (R, B) - min (r, b)) * m <min (R, B) * (c + d) + (max (R, B) - min (R, B)) * m (k是min (r, b) - N) "

 This can be seen

min( r , b ) ) * m ” == “ ( max( R , B ) - min( R , B ) ) * m ”,

It can become inequality  K * E * 2 <min (R & lt, B) * (C + D

And because " min (R & lt, B) * E 2 *> 2 * E * N (N <min (R & lt, B))" and (k> min (R, B ))

So inequality does not hold, that the above is not the optimal solution.

In summary:

"Compare" into a different box score balls into the remaining value + "and" the "size" all put in their own box scores scores of their own box is the optimal solution.

 1 #include <iostream>
 2 
 3 using namespace std;
 4 
 5 int a,b,c,d,e,ans;
 6 
 7 bool f;
 8 
 9 int main()
10 {
11     cin>>a>>b>>c>>d>>e;
12     if(a>b) f=true;
13     if(c+d>e+e) ans=a*c+b*d;
14     else 
15     {
16         if(f) ans=b*e*2+(a-b)*c;
17         else ans=a*e*2+(b-a)*d;
18     }
19     cout<<ans<<endl;
20 }

 

Lay a solid foundation, do a good job each question! ! !

Author: Gmax

This article belongs to the author and blog Park total, reproduced, please use the link, please do not reprint the original, Thanks ♪ (· ω ·) Techno

2019-08-11

Guess you like

Origin www.cnblogs.com/Gmax/p/11334276.html