Deceptive Dice (规律)

Deceptive Dice 计蒜客 - 43468

Recently your town has been infested by swindlers who convince unknowing tourists to play a simple dice game with them for money. The game works as follows: given is an n-sided die,whose sides have 1, 2, . . . , n pips, and a positive integer k. You then roll the die, and then have to make a choice. Option 1 is to stop rolling. Option 2 is to reroll the die, with the limitation that the die can only be rolled k times in total. Your score is the number of pips showing on your final roll.

Obviously the swindlers are better at this game than the tourists are. You, proud supporter of the Battle Against ProbabilisticCatastrophes, decide to fight this problem not by banning the swindlers but by arming the tourists with information.

You create pamphlets on which tourists can find the maximum expected score for many values of n and k. You are sure that the swindlers will soon stop their swindling if the tourists are better prepared than they are!

The layout of the flyers is done, and you have distribution channels set up. All that is left to do is to calculate the numbers to put on the pamphlet.

Given the number of sides of the die and the number of times you are allowed to roll, calculate the expected (that is, average) score when the game is played optimally.

image.jpg

INPUT:

• A single line with two integers 1 ≤ n ≤ 100, the number of sides of the die, and 1 ≤ k ≤ 100, the number of times the die may be rolled.

OUTPUT:

Output the expected score when playing optimally. Your answer should have an absolute or relative error of at most 10^-7.

Sample Input 4:

8 9

Sample Output 4:

7.268955230712891

样例输入
1 1
样例输出
1

题意:一个n面的筛子,至多可以投掷k次,最后一次投掷的结果就是最终结果,尽量最大,每一次投掷后,结果出来,你可以选择取消这次投掷(投掷次数要减一),在最好的策略下,结果最大值是多少

  • 例如n = 20,k = 3;
  • 第一次投掷期望值为10.5
  • 第二次投掷,因为结果要比前一次大才会取,否则取前一次的数,所以要取11-20范围内的数,结果为13
  • 第三次同理,投掷到了14-20范围的数,就取,否则取13,结果为14.4
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6+9;
int main()
{
    long long n,k;
    double ans = 0;
    cin>>n>>k;
    for(int i = 1;i<=k;i++)
    {
        long long num = floor(ans+1);
        ans = ans*(num-1.0)/n +(n+num)*(n-num+1)*1.0/n/2;
    }
    printf("%.9lf\n",ans);

    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值