首页 > 代码库 > hdu 5236 Article(概率dp)
hdu 5236 Article(概率dp)
Article
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 863 Accepted Submission(s): 309
Problem Description
As the term is going to end, DRD begins to write his final article.
DRD uses the famous Macrohard‘s software, World, to write his article. Unfortunately this software is rather unstable, and it always crashes. DRD needs to write ncharacters in his article. He can press a key to input a character at time i+0.1, where i is an integer equal or greater than 0. But at every time i−0.1 for integer istrictly greater than 0, World might crash with probability p and DRD loses his work, so he maybe has to restart from his latest saved article. To prevent write it again and again, DRD can press Ctrl-S to save his document at time i. Due to the strange keyboard DRD uses, to press Ctrl-S he needs to press x characters. If DRD has input his total article, he has to press Ctrl-S to save the document.
Since World crashes too often, now he is asking his friend ATM for the optimal strategy to input his article. A strategy is measured by its expectation keys DRD needs to press.
Note that DRD can press a key at fast enough speed.
DRD uses the famous Macrohard‘s software, World, to write his article. Unfortunately this software is rather unstable, and it always crashes. DRD needs to write ncharacters in his article. He can press a key to input a character at time i+0.1, where i is an integer equal or greater than 0. But at every time i−0.1 for integer istrictly greater than 0, World might crash with probability p and DRD loses his work, so he maybe has to restart from his latest saved article. To prevent write it again and again, DRD can press Ctrl-S to save his document at time i. Due to the strange keyboard DRD uses, to press Ctrl-S he needs to press x characters. If DRD has input his total article, he has to press Ctrl-S to save the document.
Since World crashes too often, now he is asking his friend ATM for the optimal strategy to input his article. A strategy is measured by its expectation keys DRD needs to press.
Note that DRD can press a key at fast enough speed.
Input
First line: an positive integer 0≤T≤20 indicating the number of cases.
Next T lines: each line has a positive integer n≤105, a positive real 0.1≤p≤0.9, and a positive integer x≤100.
Next T lines: each line has a positive integer n≤105, a positive real 0.1≤p≤0.9, and a positive integer x≤100.
Output
For each test case: output ‘‘Case #k: ans‘‘ (without quotes), where k is the number of the test cases, and ans is the expectation of keys of the optimal strategy.
Your answer is considered correct if and only if the absolute error or the relative error is smaller than 10−6.
Your answer is considered correct if and only if the absolute error or the relative error is smaller than 10−6.
Sample Input
21 0.5 22 0.4 2
Sample Output
Case #1: 4.000000Case #2: 6.444444
Source
hdu 5236 Article(概率dp)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。