zoukankan      html  css  js  c++  java
  • SGU 495 Kids and Prizes

    题意:给n个盒子,每个盒子里有一个礼物。有m个人,每个人拿起一个盒子,如果里面有礼物则将礼物取出并带走,无论里面有没有礼物都将盒子留下。问这m个人带走礼物数量的期望。

    解法:设d[i]表示第i个人拿盒子以后,总共带走的礼物数量的期望。d[i] = (d[i-1] + 1)* (n-d[i-1]) / n + d[i-1] * d[i-1] / n。复杂度O(m)。

       虽然解法写着很简单,但是做多了概率dp的题以后,我一来就用了别的方法来设置数组,弄了半天才做出来。

    tag:math, 概率dp

     1 /*
     2  * Author:  Plumrain
     3  * Created Time:  2013-11-12 18:35
     4  * File Name: DP-SGU-495.cpp
     5  */
     6 #include <iostream>
     7 #include <cstdio>
     8 
     9 using namespace std;
    10 
    11 int main()
    12 {
    13     int n, m;
    14     while (scanf ("%d%d", &n, &m) != EOF){
    15         double x[2] = {1.0};
    16         for (int i = 2; i <= m; ++ i){
    17             x[1] = (x[0] + 1) * (n - x[0]) / n + x[0] * x[0] / n;
    18             x[0] = x[1];
    19         }
    20         if (m > 1)
    21             printf ("%.10f
    ", x[1]);
    22         else
    23             printf ("%.10f
    ", m ? 1.0 : 0.0 );
    24     }
    25     return 0;
    26 }
    View Code
    ------------------------------------------------------------------
    现在的你,在干什么呢?
    你是不是还记得,你说你想成为岩哥那样的人。
  • 相关阅读:
    windows关闭aslr办法
    linux关闭地址空间随机化(ASLR)
    Hadoop 2.7.2 集群搭建(转载)
    ssh免密码登录
    二、hadoop文件操作
    一、hadoop安装与配置
    转载model操作
    python实现线程池
    自定义django admin及其界面
    django管理界面使用与bootstrap模板使用
  • 原文地址:https://www.cnblogs.com/plumrain/p/SGU_495.html
Copyright © 2011-2022 走看看