Funfair
Time limit2sMemory limit512 MB
Pick and order k games from n so the expected final money is maximized, then report that value.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Sorting, Probability
- Solved
- No attempts yet
Problem
A funfair has games . You pick of them and play each picked game once, in an order of your choice. You cannot play the same game twice, and you must fix both the games and their order before the first game starts.
You start with Oshloobs. Suppose you hold Oshloobs when game begins. If you win it, your money becomes . If you lose it, you lose percent of , so your money becomes . You win game with probability percent, and the games are independent of each other.
Choose the games and their order so that the expected amount of money you hold after playing all of them is as large as possible, and report that expected amount.
Input
The input holds several test cases.
The first line of each test case has three space separated integers , , and (, ). Each of the next lines describes game with three space separated integers , , and ().
The last line of the input is 0 0 0. It is not a test case, so do not process it.
Output
For each test case, print on one line the maximum expected amount of final money, rounded to exactly two digits after the decimal point. Always print both digits.
A value exactly halfway rounds up, so prints as 1.01. Every answer in the test data is farther than from a halfway point, so double precision arithmetic gives the same digits.