• Random Sequence 2011ACM福州赛区网络赛


    Random Sequence

    Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 202    Accepted Submission(s): 124


    Problem Description
    There is a random sequence L whose element are all random numbers either -1 or 1 with the same possibility. Now we define MAVS, the abbreviate of Maximum Absolute Value Subsequence, to be any (if more than one) subsequences of L whose absolute value is maximum among all subsequences. Given the length of L, your task is to find the expectation of the absolute value of MAVS.
     

    Input
    There is only one input file. The first line is the number of test cases T. T positive integers follow, each of which contains one positive number not greater than 1500 denoted the length of L.
     

    Output
    For each test case, output the expectation you are required to calculate. Answers are rounded to 6 numbers after the decimal point.(as shown in the sample output)
     

    Sample Input
    3 1 5 10
     

    Sample Output
    Case 1: 1.000000 Case 2: 2.750000 Case 3: 4.167969
     

    Source
     

    Recommend
    lcy
     
     
    数论神题啊!!!!
    卡特兰数
    #include<iostream>
    #include<iomanip>
    #include<cstring>
    #include<cmath>
    using namespace std;
    long double a[2000];
    long double p;
    long double C(int n){
    long double t=1;
    for(int i=n+1;i<=2*n+1;i++){

    t*=i;
    t/=i-n;

    }
    // for(int i=1;i<=n+1;i++) t/=i;
    return t;
    }

    int main(){
    int t,n,cnt=0;
    a[1]=1;
    for(int i=2;i<=1500;i++){
    if(i%2==0) a[i]=(a[i-1]*2+C(i/2-1));
    else a[i]=(a[i-1]*2+C(i/2-1)*2);
    //cout<<"i="<<i<<","<<a[i]<<endl;
    }

    cin>>t;
    while(t--){
    cin>>n;
    p=pow(2.0,n-1);

    cout<<"Case "<<++cnt<<": "<<fixed<<setprecision(6)<<a[n]/p<<endl;
    }
    // system("pause");
    return 0;
    }
  • 相关阅读:
    js外观模式
    微服务架构的基础框架选择:Spring Cloud还是Dubbo?
    JAVA 中BIO,NIO,AIO的理解
    Reactor和Proactor模式的讲解(关于异步,同步,阻塞与非阻塞)
    JVM(Java虚拟机)优化大全和案例实战
    php编译安装后,加扩展模块
    mysql查所有列名
    cannot get uid for user 'www'
    rabbitmq management Login Failed
    nginx 安装过程中的not found
  • 原文地址:https://www.cnblogs.com/kuangbin/p/2210930.html
Copyright © 2020-2023  润新知