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;}