Hdu 4811 Ball (Mathematics)

Source: Internet
Author: User

Link: hdu 4811 Ball

There are several balls in three colors. Each time you put a ball on the table, it must be a sequence, the score for each ball placement is the number of different colors a before the current ball in the sequence, and the number of different colors B, a + B. Q: The maximum score for a given number of balls.

Solution: because the order of putting the ball is determined by ourselves, we can construct a sequence as early as possible so that the scores of the following fl are kept at the peak. The peak value is determined by the number of balls. We call the score as the peak value the highest score. There are many of them. For a color: 0 indicates that the score cannot be left or right of the top score. In other words, the score cannot be set, create a score either on the left or on the right. Create two scores on each of the two sides. Two or more sides have no meaning, so they still have two scores.
The peak value is obtained, and the rest is much simpler.

#include 
  
   #include 
   
    #include 
    
     #include using namespace std;typedef long long ll;inline ll cal (ll u) {    if (u <= 2)        return u;    else        return 2;}int main () {    ll R, Y, B;    while (cin >> R >> Y >> B) {        ll h = cal(R) + cal(Y) + cal(B);        ll n = R + Y + B;        ll ans = 0;        for (ll i = 0; i < n && i < h; i++)            ans += i;        if (n > h)            ans += h * (n-h);;        cout << ans << endl;    }        return 0;}
    
   
  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.