# 【BZOJ-1426】收集邮票 概率与期望DP

## 1426: 收集邮票

Time Limit: 1 Sec  Memory Limit: 162 MB
Submit: 261  Solved: 209
[Submit][Status][Discuss]

3

21.25

## Solution

$$g[i]=\sum _{x=0}^{\infty }x*P(x,i)$$

$$g[i]=g[i]*\frac{i}{n}+g[i+1]*\frac{n-i}{n}+1$$

$$g[i]-g[i]*\frac{i}{n}=g[i+1]*\frac{n-i}{n}+1$$

$$g[i]*\frac{n-i}{n}=g[i+1]*\frac{n-i}{n}+1$$

$$g[i]=(g[i+1]*\frac{n-i}{n}+1)*\frac{n}{n-i}$$

$$f[i][j]=\frac{i}{n}*f[i][j+1]+\frac{n-i}{n}*f[i+1][j+1]+j$$

$$f[i][j]=\sum_{x=0}^{\infty }[j+(j+1)+...+(x+j-1)]*P(x,i)$$

$$f[i][j]=\sum _{x=0}^{\infty }\frac{x*[(j)+(x+j-1)]}{2}*P(x,i)$$

$$f[i][j+1]-f[i][j]=\sum_{x=0}^{\infty}x*P(x,i) \Leftrightarrow f[i][j+1]-f[i][j]=g[i]$$

$$f[i][j]=f[i][j+1]*\frac{i}{n}+f[i+1][j+1]*\frac{n-i}{n}$$

$$\Rightarrow f[i][j]=(f[i][j]+g[i])*\frac{i}{n}+(f[i+1][j]+g[i+1])*\frac{n-i}{n}+j$$

$$f[i][j]=\frac{[(f[i+1][j]+g[i+1])*\frac{n-i}{n}+g[i]*\frac{i}{n}+j]*n}{n-i}$$

$$f[i]=f[i+1]+g[i+1]+g[i]*\frac{i}{n-i}+\frac{n}{n-i}$$

## Code

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
#define MAXN 10010
int N;
double g[MAXN],f[MAXN];
int main()
{
scanf("%d",&N);
for (int i=N-1; i>=0; i--) g[i]=g[i+1]+1.0*N/(N-i);
for (int i=N-1; i>=0; i--) f[i]=f[i+1]+g[i+1]+g[i]*1.0*i/(N-i)+1.0*N/(N-i);
printf("%.2lf\n",f[0]);
}


posted @ 2016-09-24 21:53  DaD3zZ  阅读(1693)  评论(1编辑  收藏  举报