Problem
You have been invited to the popular TV show "Would you like to be a millionaire?". Of course you would!
The rules of the show are simple:
Given M, P and X, determine your probability of winning at least $1000000 if you play optimally (i.e. you play so that you maximize your chances of becoming a millionaire).
Input
The first line of input gives the number of cases, N.
Each of the following N lines has the format "M P X", where:
- M is an integer, the number of rounds of betting.
- P is a real number, the probability of winning each round.
- X is an integer, the starting number of dollars.
Output
For each test case, output one line containing "Case #X: Y", where:
- X is the test case number, beginning at 1.
- Y is the probability of becoming a millionaire, between 0 and 1.
Answers with a relative or absolute error of at most 10-6 will be considered correct.
Limits
1 ≤ N ≤ 100
0 ≤ P ≤ 1.0, there will be at most 6 digits after the decimal point.
1 ≤ X ≤ 1000000
Small dataset
1 ≤ M ≤ 5
Large dataset
1 ≤ M ≤ 15
Sample
Input |
Output |
2 1 0.5 500000 3 0.75 600000
|
Case #1: 0.500000 Case #2: 0.843750
|
In the first case, the only way to reach $1000000 is to bet everything in the single round.
In the second case, you can play so that you can still reach $1000000 even if you lose a bet. Here's one way to do it:
- You have $600000 on the first round. Bet $150000.
- If you lose the first round, you have $450000 left. Bet $100000.
- If you lose the first round and win the second round, you have $550000 left. Bet $450000.
- If you win the first round, you have $750000 left. Bet $250000.
- If you win the first round and lose the second round, you have $500000 left. Bet $500000.
这道题是一个不是很明显的概率DP,题意是你要进行M轮的赌博,一开始你有初始金额X , 你每一轮获胜的概率都为P,当你最后持有的金钱 >= 1000000时算作取胜,给你M , P , X , 让你输出取胜的概率。
首先,由于赌注随意,可以为小数,所以无法直接暴枚,这里我们就会用到一个技巧“化连续为离散”。我们从最后一轮开始分类讨论,显然,最后一轮只有三种情况0 --- 500000 , 500000 --- 1000000 , 1000000 --- ;第一种获胜的概率为0,第二种为P,第三种为1。然后,我们再看倒数第二轮,分为5种状态:0 --- 250000 , 250000 --- 500000 , 500000 --- 750000 , 750000 --- 1000000 , 1000000 --- ;然后我们便得出第i轮的情况有2的i次幂 + 1种。然后枚举每种情况的期望,找到最优步骤即可。
#include
#include
#include
#include
#include
#include