zoukankan      html  css  js  c++  java
  • [BZOJ1426]收集邮票(概率期望dp)

    题面

    https://darkbzoj.tk/problem/1426

    题解

    (Pr(i,j))为买了i次,正好买到j种票的概率。(“正好”的含义是:第i次刚好解锁一种新的票)

    则所求答案为(sum_{x}{frac{x(x+1)}{2}}Pr(x,n))

    将其拆开,设(sum_x{x^2}Pr(x,i)=f_2[i],sum_x{xPr(x,i)}=f_1[i])

    [f_1[i+1]=sumlimits_{x}xPr(x,i+1) ]

    [=sumlimits_{x}x{sumlimits_{j=0}^{x-1}}Pr(j,i){frac{i^{x-j-1}*(n-i)}{n^{x-j}}} ]

    [={sumlimits_{j=0}^{+infty}}Pr(j,i)sumlimits_{x=j+1}^{+infty}x{frac{i^{x-j-1}*(n-i)}{n^{x-j}}} ]

    [={sumlimits_{j=0}^{+infty}}Pr(j,i)sumlimits_{d=1}^{+infty}(d+j){frac{i^{d-1}*(n-i)}{n^{d}}} ]

    [=sumlimits_{j=0}^{+infty}Pr(j,i){ imes}{frac{n-i}{i}}sumlimits_{d=1}^{+infty}(d+j)(frac{i}{n})^{d} ]

    [=sumlimits_{j=0}^{+infty}Pr(j,i){ imes}{frac{n-i}{i}}(jsumlimits_{d=1}^{+infty}(frac{i}{n})^{d}+sumlimits_{d=1}^{+infty}d(frac{i}{n})^d) ]

    [=sumlimits_{j=0}^{+infty}Pr(j,i){ imes}{frac{n-i}{i}}(j*{frac{i}{n-i}}+{frac{ni}{(n-i)^2}}) ]

    [=sumlimits_{j=0}^{+infty}Pr(j,i)(j+{frac{n}{(n-i)}}) ]

    由于(sum_{j=0}^{+infty}Pr(j,i)j=f_1[i])以及(sum_{j=0}^{+infty}Pr(j,i)=1),得到

    [f_1[i+1]=f_1[i]+{frac{n}{n-i}} ]

    f2也类似:

    [f_2[i+1]=sumlimits_{x}x^2Pr(x,i+1) ]

    [=sumlimits_{x}x^2{sumlimits_{j=0}^{x-1}}Pr(j,i){frac{i^{x-j-1}*(n-i)}{n^{x-j}}} ]

    [={sumlimits_{j=0}^{+infty}}Pr(j,i)sumlimits_{x=j+1}^{+infty}x^2{frac{i^{x-j-1}*(n-i)}{n^{x-j}}} ]

    [={sumlimits_{j=0}^{+infty}}Pr(j,i)sumlimits_{d=1}^{+infty}(d+j)^2{frac{i^{d-1}*(n-i)}{n^{d}}} ]

    [=sumlimits_{j=0}^{+infty}Pr(j,i){ imes}{frac{n-i}{i}}sumlimits_{d=1}^{+infty}(d^2+2dj+j^2)(frac{i}{n})^{d} ]

    [=sumlimits_{j=0}^{+infty}Pr(j,i){ imes}{frac{n-i}{i}}(j^2sumlimits_{d=1}^{+infty}(frac{i}{n})^{d}+ 2jsumlimits_{d=1}^{+infty}{d(frac{i}{n})^d}+sumlimits_{d=1}^{+infty}d^2(frac{i}{n})^d) ]

    [=sumlimits_{j=0}^{+infty}Pr(j,i){ imes}{frac{n-i}{i}}(j^2{frac{i}{n-i}}+ 2j{frac{ni}{(n-i)^2}}+sumlimits_{d=1}^{+infty}d^2(frac{i}{n})^d) ]

    其中(sum_{d=1}^{+infty}d^2(frac{i}{n})^d)可以用扰动法求解:

    [S=sumlimits_{d=1}^{+infty}d^2(frac{i}{n})^d ]

    [=sumlimits_{d=0}^{+infty}(d+1)^2(frac{i}{n})^{d+1} ]

    [=frac{i}{n}sumlimits_{d=0}^{+infty}(d^2+2d+1)(frac{i}{n})^d ]

    [=frac{i}{n}(sumlimits_{d=0}^{+infty}d^2(frac{i}{n})^d+2sumlimits_{d=0}^{+infty}d(frac{i}{n})^d+sumlimits_{d=0}^{+infty}(frac{i}{n})^d) ]

    [=frac{i}{n}(S+2 imesfrac{ni}{(n-i)^2}+frac{n}{n-i}) ]

    所以算出(S=frac{ni^2+n^2i}{(n-i)^3})。代入原式,可得

    [f_2[i+1]=sumlimits_{j=0}^{+infty}Pr(j,i){ imes}{frac{n-i}{i}}(j^2{frac{i}{n-i}}+ 2j{frac{ni}{(n-i)^2}}+frac{ni^2+n^2i}{(n-i)^3}) ]

    [=sumlimits_{j=0}^{+infty}Pr(j,i)(j^2+frac{2jn}{n-i}+frac{ni+n^2}{(n-i)^2}) ]

    [=f_2[i]+frac{2n}{n-i}f_1[i]+frac{ni+n^2}{(n-i)^2} ]

    所以有了下面两个式子:

    [egin{cases} f_1[i+1]=f_1[i]+{frac{n}{n-i}} \ f_2[i+1]=f_2[i]+frac{2n}{n-i}f_1[i]+frac{ni+n^2}{(n-i)^2} end{cases} ]

    就可以展开递推求解(f_1,f_2)。最后的答案就是(frac{f_1[n]+f_2[n]}{2})

    代码

    此题笔头工作很多,代码几乎没有

    #include<bits/stdc++.h>
    
    using namespace std;
    
    #define rg register
    #define In inline
    
    const int N = 1e4;
    
    In double sqr(double x){
    	return x * x;
    }
    
    int n;
    double f1[N+5],f2[N+5];
    
    int main(){
    	cin >> n;
    	for(rg int i = 0;i < n;i++){
    		f1[i+1] = f1[i] + 1.0 * n / (n - i);
    		f2[i+1] = f2[i] + f1[i] * 2 * n / (n - i) + (n * i + n * n) / sqr(n - i);
    	}
    	printf("%.2f
    ",0.5 * (f1[n]+f2[n]));
    	return 0;
    }
    
  • 相关阅读:
    Tarjan算法求双连通分量
    Tarjan
    前端技术实现js图片水印
    记录一下ionic canvas图片,还有canvas里面的图片跨域的问题
    ionic cordova screenshot 使用和操作
    关于ionic2 更新到ionic3 后组件不能用的解决方案
    背景图处理,这是个好东西记录一下
    radio样式的写法,单选和多选如何快速的改变默认样式,纯CSS,
    ionic使用cordova插件中的Screenshot截图分享功能
    ionic中执行pop返回上一个页面,还需要执行操作
  • 原文地址:https://www.cnblogs.com/xh092113/p/12438705.html
Copyright © 2011-2022 走看看