luogu#P5155. [USACO18DEC] Balance Beam P
[USACO18DEC] Balance Beam P
Problem Description
To save money to build a new stall in her barn, Bessie starts performing at a local circus, showing off her excellent balance by carefully walking back and forth on a balance beam.
How much money Bessie can earn depends on the position where she finally jumps off the beam successfully. Positions on the beam from left to right are labeled . If Bessie reaches position or , she will fall off the end of the beam and unfortunately receive no reward.
If Bessie is at a given position , she may do either of the following:
-
Toss a coin. If it lands tails up, she moves to position ; if it lands heads up, she moves to position (that is, each happens with probability ).
-
Jump off the beam and receive a reward of ().
Bessie realizes she cannot guarantee getting any particular reward, since her movement is controlled by the random coin tosses. However, based on her starting position, she wants to compute the expected reward she can obtain after making a sequence of optimal decisions (where “optimal” means the decisions that yield the highest possible expected reward).
For example, if her strategy gives her a reward of with probability , a reward of with probability , and a reward of with probability , then her expected reward is the weighted average .
Input Format
The first line of input contains (). The next lines contain .
Output Format
Output lines. On the -th line, output times the expected reward Bessie can obtain when starting from position and using an optimal strategy, rounded down.
2
1
3
150000
300000
Hint
Translated by ChatGPT 5