题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=385

题意:

思路:

double f[N][N][N],g[N][N],A[N][N];
int n;

void init()
{
    int i,j;
    for(i=2;i<=100;i++)
    {
        A[i][1]=i;
        for(j=2;j<=i;j++) A[i][j]=A[i][j-1]*(i+1-j);
    }
}

double DFS(int,int,int);

double dfs(int i,int j)
{
    if(g[i][j]>=0) return g[i][j];
    if(j>i) return 0;
    int k;
    g[i][j]=0;
    for(k=1;k*j<=i;k++) g[i][j]+=DFS(i,j,k);
    return g[i][j];
}

double DFS(int i,int j,int k)
{
    if(f[i][j][k]>=0) return f[i][j][k];
    if(i<=1||j<=1||k<=0||k*j>i||i<j) return 0;
    if(i==j&&k==1) return A[n][i]/i;
    f[i][j][k]=DFS(i-j,j,k-1)*A[n-i+j][j]/j/k;
    if(k==1)
    {
        int t,L=min(j-1,i-j);
        double temp=A[n-i+j][j]/j;
        for(t=2;t<=L;t++) f[i][j][k]+=dfs(i-j,t)*temp;
    }
    return f[i][j][k];
}

int main()
{
    init();
    Rush(n)
    {
        clr(f,-1); clr(g,-1);
        double s1=0,s2=0;
        int j,k;
        for(j=2;j<=n;j++) for(k=1;k<=n;k++)
        {
            s1+=j*k*DFS(n,j,k);
            s2+=DFS(n,j,k);
        }
        double ans=s1/s2;
        printf("%.10lf\n",ans);
    }
}

  

SGU 385 Highlander(期望)的更多相关文章

  1. SGU 495 Kids and Prizes:期望dp / 概率dp / 推公式

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=495 题意: 有n个礼物盒,m个人. 最开始每个礼物盒中都有一个礼物. m个人依次随 ...

  2. sgu 495. Kids and Prizes (简单概率dp 正推求期望)

    题目链接 495. Kids and Prizes Time limit per test: 0.25 second(s)Memory limit: 262144 kilobytes input: s ...

  3. SGU 495. Kids and Prizes( 数学期望 )

    题意: N个礼品箱, 每个礼品箱内的礼品只有第一个抽到的人能拿到. M个小孩每个人依次随机抽取一个,  求送出礼品数量的期望值. 1 ≤ N, M ≤ 100, 000 挺水的说..设f(x)表示前x ...

  4. 【SGU】495. Kids and Prizes

    http://acm.sgu.ru/problem.php?contest=0&problem=495 题意:N个箱子M个人,初始N个箱子都有一个礼物,M个人依次等概率取一个箱子,如果有礼物则 ...

  5. SGU 176 Flow construction(有源汇上下界最小流)

    Description 176. Flow construction time limit per test: 1 sec. memory limit per test: 4096 KB input: ...

  6. 【专题】概率期望DP

    11.22:保持更新状态:主要发一些相关的题目和个人理解 (P.S.如果觉得简单,可以直接看后面的题目) upd 11.30 更完了 [NO.1] UVA12230 Crossing Rivers  ...

  7. 【BZOJ-3143】游走 高斯消元 + 概率期望

    3143: [Hnoi2013]游走 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 2264  Solved: 987[Submit][Status] ...

  8. bzoj1415[NOI2005]聪聪和可可-期望的线性性

    这道题之前我写过一个巨逗比的写法(传送门:http://www.cnblogs.com/liu-runda/p/6220381.html) 当时的原因是这道题可以抽象出和"绿豆蛙的归宿&qu ...

  9. hdu 4481 Time travel(高斯求期望)(转)

    (转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...

随机推荐

  1. Leetcode#145 Binary Tree Postorder Traversal

    原题地址 递归写法谁都会,看看非递归写法. 对于二叉树的前序和中序遍历的非递归写法都很简单,只需要一个最普通的栈即可实现,唯独后续遍历有点麻烦,如果不借助额外变量没法记住究竟遍历了几个儿子.所以,最直 ...

  2. CIFAR-10 Competition Winners: Interviews with Dr. Ben Graham, Phil Culliton, & Zygmunt Zając

    CIFAR-10 Competition Winners: Interviews with Dr. Ben Graham, Phil Culliton, & Zygmunt Zając Dr. ...

  3. Deep Learning: Assuming a deep neural network is properly regulated, can adding more layers actually make the performance degrade?

    Deep Learning: Assuming a deep neural network is properly regulated, can adding more layers actually ...

  4. 将HTMLCollection/NodeList/伪数组转换成数组

    这里把符合以下条件的对象称为伪数组(ArrayLike) 1,具有length属性 2,按索引方式存储数据 3,不具有数组的push,pop等方法 如 1,function内的arguments . ...

  5. tomcat 常见错误

    1.启动时加载会话错误 Exception loading sessions from persistent storage 处理方法:删除tomcat对应的项目目录下 work/session.se ...

  6. iOS富文本-NSAttributedString简单封装

    直接调用系统的写起来比较麻烦,封装一下 因为要简单所以就写类方法 WJAttributeStyle 基类 ) {         ; i < styles.count; i ++) {      ...

  7. 无限互联IOS电影项目视频笔记

    下面是该iOS项目视频教程的内容大纲: 观看指南 (1)项目为第一阶段内容 (2)需要熟练掌握OC语言 (3)UI部分需要学习到第十节课 (4)项目适合刚入门的iOS开发者 1.第一天 (1)iOS ...

  8. Codeforces Round #263 (Div. 2) D. Appleman and Tree(树形DP)

    题目链接 D. Appleman and Tree time limit per test :2 seconds memory limit per test: 256 megabytes input ...

  9. Appium入门示例(python)

    安装Python依赖 pip3.4 install nose pip3.4 install selenium pip3.4 install Appium-Python-Client 运行测试用例and ...

  10. lintcode :最长公共前缀

    题目 最长公共前缀 给k个字符串,求出他们的最长公共前缀(LCP) 样例 在 "ABCD" "ABEF" 和 "ACEF" 中,  LCP ...