20年ICPC澳门站L - Random Permutation

An integer sequence with length nn, denoted by a_1,a_2,\cdots,a_na1​,a2​,⋯,an​, is generated randomly, and the probability of being 1,2,\cdots,n1,2,⋯,n are all \frac{1}{n}n1​ for each a_iai​ (i=1,2,\cdots,n)(i=1,2,⋯,n).

Your task is to calculate the expected number of permutations p_1,p_2,\cdots,p_np1​,p2​,⋯,pn​ from 11 to nn such that p_i \le a_ipi​≤ai​ holds for each i=1,2,\cdots,ni=1,2,⋯,n.

Input

The only line contains an integer nn (1 \leq n \leq 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^{-9}10−9.

Formally speaking, suppose that your output is xx and the jury's answer is yy. Your output is accepted if and only if \frac{|x - y|}{\max(1, |y|)} \leq 10^{-9}max(1,∣y∣)∣x−y∣​≤10−9.

InputcopyOutputcopy
2
1.000000000000

Sample 2

InputcopyOutputcopy
3
1.333333333333

Sample 3

InputcopyOutputcopy
50
104147662762941310907813025277584020848013430.758061352192

题意:长度为n的a数组中,每个数是1,2,3,4..n的概率都是1/n,对于全排列的p数组(如1,2,3。1,3,2。2,1,3。2,3,1。3,1,2。3,2,1),全部下标i都成立的pi<=ai的数学期望是多少。

题意比较难懂,就是所有全排列的p数组答案+起来。p数组为1,2时,答案是2/4,因为a数组有1,2。2,2可以,两个的概率是2/4=0.5;

p数组为2,1时,可以算出答案也是0.5,最后数学期望和就是1.000000。

思路:答案简单算算可以知道为:(n!*n!)/n^n。没有公式直接算即可。

,他的意思应该是前10位对就ok,所以c++的long double和py直接小数计算都可

 代码:

#include<bits/stdc++.h>
using namespace std;
#define fo(a,b) for(int i=a;i<=b;i++)
#define inf 0x3f3f3f3f
#define dou long double
#define M 100005
dou res=1,n;
int main(){
    cin>>n;
    for(dou i=1;i<=n;i++){
        res*=i*i/n;
    }
    printf("%.15Lf\n",res);
    return 0;
}

py代码:

n=(int)(input())
res=1
for i in range(1,n+1):
    res*=1.0/n*i*i
print(res)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

int 我

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值