[BZOJ1426]收集郵票(概率期望dp)
阿新 • • 發佈:2020-10-05
題面
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]=\sum\limits_{x}xPr(x,i+1) \]\[=\sum\limits_{x}x{\sum\limits_{j=0}^{x-1}}Pr(j,i){\frac{i^{x-j-1}*(n-i)}{n^{x-j}}} \]由於\(\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]=\sum\limits_{x}x^2Pr(x,i+1) \]\[=\sum\limits_{x}x^2{\sum\limits_{j=0}^{x-1}}Pr(j,i){\frac{i^{x-j-1}*(n-i)}{n^{x-j}}} \]\[={\sum\limits_{j=0}^{+\infty}}Pr(j,i)\sum\limits_{x=j+1}^{+\infty}x^2{\frac{i^{x-j-1}*(n-i)}{n^{x-j}}} \]\[={\sum\limits_{j=0}^{+\infty}}Pr(j,i)\sum\limits_{d=1}^{+\infty}(d+j)^2{\frac{i^{d-1}*(n-i)}{n^{d}}} \]\[=\sum\limits_{j=0}^{+\infty}Pr(j,i){\times}{\frac{n-i}{i}}\sum\limits_{d=1}^{+\infty}(d^2+2dj+j^2)(\frac{i}{n})^{d} \]\[=\sum\limits_{j=0}^{+\infty}Pr(j,i){\times}{\frac{n-i}{i}}(j^2\sum\limits_{d=1}^{+\infty}(\frac{i}{n})^{d}+ 2j\sum\limits_{d=1}^{+\infty}{d(\frac{i}{n})^d}+\sum\limits_{d=1}^{+\infty}d^2(\frac{i}{n})^d) \]\[=\sum\limits_{j=0}^{+\infty}Pr(j,i){\times}{\frac{n-i}{i}}(j^2{\frac{i}{n-i}}+ 2j{\frac{ni}{(n-i)^2}}+\sum\limits_{d=1}^{+\infty}d^2(\frac{i}{n})^d) \]其中\(\sum_{d=1}^{+\infty}d^2(\frac{i}{n})^d\)可以用擾動法求解:
\[S=\sum\limits_{d=1}^{+\infty}d^2(\frac{i}{n})^d \]\[=\sum\limits_{d=0}^{+\infty}(d+1)^2(\frac{i}{n})^{d+1} \]\[=\frac{i}{n}\sum\limits_{d=0}^{+\infty}(d^2+2d+1)(\frac{i}{n})^d \]\[=\frac{i}{n}(\sum\limits_{d=0}^{+\infty}d^2(\frac{i}{n})^d+2\sum\limits_{d=0}^{+\infty}d(\frac{i}{n})^d+\sum\limits_{d=0}^{+\infty}(\frac{i}{n})^d) \]\[=\frac{i}{n}(S+2\times\frac{ni}{(n-i)^2}+\frac{n}{n-i}) \]所以算出\(S=\frac{ni^2+n^2i}{(n-i)^3}\)。代入原式,可得
\[f_2[i+1]=\sum\limits_{j=0}^{+\infty}Pr(j,i){\times}{\frac{n-i}{i}}(j^2{\frac{i}{n-i}}+ 2j{\frac{ni}{(n-i)^2}}+\frac{ni^2+n^2i}{(n-i)^3}) \]\[=\sum\limits_{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} \]所以有了下面兩個式子:
\[\begin{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\n",0.5 * (f1[n]+f2[n]));
return 0;
}