CF2181J.Jinx or Jackpot
提高+/省选-
通过率:0%
时间限制:3.00s
内存限制:1024MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Jack is in his favourite casino and has 1000 dollars. The casino has literally nothing but a single slot machine. Jack knows the history of this casino. Once upon a time, the future owner of the casino was walking and suddenly saw an array of n integer choices p1,…,pn each from 0 to 100. He picked an index i (1≤i≤n) uniformly at random and thought that it was a good idea to create a casino in which there is only one slot machine with jackpot probability of 100pi. And he created it.
Jack knows the array of choices p1,…,pn that suddenly appeared to the owner during the walk, but he does not know which i the owner picked. However, the chosen index i is fixed forever; the slot machine always uses the same pi as explained below.
On the slot machine, Jack can bet x dollars, where x is a non-negative integer, and pull the lever. Then:
- With probability 100pi it will be a jackpot, and the slot machine returns 2x dollars to him, so he gains x dollars.
- With probability 1−100pi it will be a jinx, and the slot machine returns nothing to him, so he loses x dollars.
Even if Jack bets 0 dollars, he will understand whether it was a jinx or a jackpot.
Also, the slot machine is not very durable, so Jack can play at most k rounds on it.
Find the maximum expected profit Jack can achieve by an optimal strategy. Here a profit is defined as the final amount of money Jack has minus his initial 1000 dollars.
Of course, Jack can't make a bet that is more than his current balance.
杰克正在他最喜欢的赌场里,身上有 1000 美元。这家赌场里只有一台老虎机。杰克了解这家赌场的历史:很久以前,这家赌场未来的老板在路上散步时,突然看到了一个由 n 个整数 p1,…,pn 组成的数组,其中每个 pj 均在 0 到 100 之间(含端点)。他从 1 到 n 中均匀随机地选取了一个下标 i(即 1≤i≤n),并认为以 100pi 为中奖概率设置一台老虎机是个不错的主意——于是他就照此建起了这家赌场。
杰克知道老板散步时偶然看到的那个数组 p1,…,pn,但他并不知道老板当时究竟选中了哪一个下标 i。然而,这个被选中的下标 i 是永久固定的;如前所述,这台老虎机始终使用同一个 pi。
在该老虎机上,杰克每次可以下注 x 美元,其中 x 是一个非负整数,然后拉动拉杆。此时:
- 以概率 100pi 触发“头奖”(jackpot),老虎机返还 2x 美元,因此杰克净赚 x 美元;
- 以概率 1−100pi 触发“厄运”(jinx),老虎机不返还任何钱,因此杰克净亏 x 美元。
即使杰克下注 0 美元,他仍能获知本次结果是“厄运”还是“头奖”。
此外,这台老虎机不够耐用,杰克最多只能玩 k 轮。
请计算杰克通过最优策略所能获得的最大期望收益。此处“收益”定义为:杰克最终拥有的钱数减去其初始资金 1000 美元。
当然,杰克不能下注超过其当前余额的金额。
输入格式
The first line contains two integers n and k (1≤n≤100000; 1≤k≤30) — the number of choices and the limit on the number of rounds. The second line contains n integers p1,…,pn (0≤pi≤100) — the choices.
第一行包含两个整数 n 和 k(1≤n≤100000;1≤k≤30)—— 分别表示选项数量和轮次上限。
第二行包含 n 个整数 p1,…,pn(0≤pi≤100)—— 表示各个选项。
输出格式
Output a single real number — the expected profit Jack can achieve by an optimal strategy. Your answer will be considered correct if its absolute or relative error is at most 10−4.
输出一个实数——Jack 通过最优策略所能获得的期望收益。若你的答案的绝对误差或相对误差不超过 10−4,则视为正确。
输入输出样例
输入#1
2 2 70 30
输出#1
160
输入#2
2 30 30 70
输出#2
12099716.1778528057038784
输入#3
2 5 40 50
输出#3
0
输入#4
6 6 10 20 60 30 40 50
输出#4
29.40799999999990177457221
输入#5
1 5 61
输出#5
1702.708163199999489734182
输入解题思路,AI测评打分。不知道怎么写?