#PU864. USACO 2018 December Contest, Platinum — Problem 1. Balance Beam
USACO 2018 December Contest, Platinum — Problem 1. Balance Beam
USACO 2018 December Contest, Platinum — Problem 1. Balance Beam
题目描述
In order to save money for a new stall in her barn, Bessie the cow
has started performing in the local circus, demonstrating her remarkable
sense of balance as she carefully walks back and forth on an elevated
balance beam!
The amount of money Bessie earns in her performance is
related to where she manages to ultimately jump off the beam.
The beam has positions labeled from left to right.
If Bessie ever reaches or she falls off one of the ends
of the beam and sadly gets no payment.
If Bessie is at a given position , she can do either of the following:
- Flip a coin. If she sees tails, she goes to position , and if she sees heads, she goes to position (i.e. probability of either occurrence).
- Jump off the beam and receive payment of . Bessie realizes that she may not be able to guarantee any particular payment outcome, since her movement is governed by random coin flips. However, based on the location where she starts, she wants to determine what her expected payment will be if she makes an optimal sequence of decisions ("optimal" meaning that the decisions lead to the highest possible expected payment). For example, if her strategy earns her payment of with probability , with probability , or with probability , then her expected payment will be the weighted average .
输入格式
The first line of input contains (). Each of the remaining lines contain .
输出格式
(见题面原文)
数据范围
(见题面原文)
样例
样例 1
2
1
3
150000
300000
Problem credits: Franklyn Wang and Spencer Compton