• The 2020 ICPC Asia Macau Regional Contest L Random Permutation(概率期望/思维)


    An integer sequence with length n, denoted by 1,2,⋯,a1,a2,⋯,an, is generated randomly, and the probability of being 1,2,⋯,1,2,⋯,n are all 11n for each ai (=1,2,⋯,)(i=1,2,⋯,n).

    Your task is to calculate the expected number of permutations 1,2,⋯,p1,p2,⋯,pn from 11 to nsuch that ≤pi≤ai holds for each =1,2,⋯,i=1,2,⋯,n.

    Input

    The only line contains an integer n (1≤≤50)(1≤n≤50).

    Output

    Output the expected number of permutations satisfying the condition. Your answer is acceptable if its absolute or relative error does not exceed 10−910−9.

    Formally speaking, suppose that your output is x and the jury's answer is y. Your output is accepted if and only if |−|max(1,||)≤10−9|x−y|max(1,|y|)≤10−9.

    Examples

    input

    Copy

    2
    

    output

    Copy

    1.000000000000
    

    input

    Copy

    3
    

    output

    Copy

    1.333333333333
    

    input

    Copy

    50
    

    output

    Copy

    104147662762941310907813025277584020848013430.758061352192
    

    首先易知可能的a序列总共有\(n^n\)个。p序列一共有\(n!\)种可能(因为是1~n排列),对于每种排列,满足条件的a序列有\(n!\)个,因为对于\(p_1,p_2...p_n\),a序列只能这样选:\([p1, n], [p2, n]...[pn, n]\),且p1到pn是一个1到n的排列。注意因为是求期望,所以不用考虑重复的情况。

    import math
    n = eval(input())
    print((math.factorial(n)) ** 2 / n ** n)
    
    
  • 相关阅读:
    C#8.0——异步流(AsyncStream)
    递归,循环,尾递归
    C#7.2——编写安全高效的C#代码
    Ocelot中文文档-Route
    Ocelot中文文档-Configuration
    Ocelot中文文档-Not Supported
    Ocelot中文文档-Getting Started
    .NET 单元测试的利剑——模拟框架Moq(简述篇)
    输入五个数字,按从大到小的顺序输出
    函数和方法的区别
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/15517746.html
Copyright © 2020-2023  润新知