HDU4652 Dice

Link

\(\text{Part.1}\)

\(f_i\)为结束时序列长度为\(i\)的概率,其PGF为\(F(x)\)
\(g_i\)为序列长度达到\(i\)且尚未结束的概率,其OGF为\(G(x)\)
分析可得:

\[\begin{aligned} F(x)+G(x)&=xG(x)+1\\ (\frac xm)^{n-1}G(x)&=\sum\limits_{i=1}^n(\frac xm)^{n-i}F(x) \end{aligned} \]

解得\(ans=F'(1)=\sum\limits_{i=0}^{n-1}m^i\)

\(\text{Part.2}\)

\(f_i\)为结束时序列长度为\(i\)的概率,其PGF为\(F(x)\)
\(g_i\)为序列长度达到\(i\)且尚未结束的概率,其OGF为\(G(x)\)
分析可得:

\[\begin{aligned} F(x)+G(x)&=xG(x)+1\\ (\frac xm)^n\frac{m!}{(m-n)!}G(x)&=\sum\limits_{i=1}^n(\frac xm)^{n-i}\frac{(m-i)!}{(m-n)!}F(x) \end{aligned} \]

解得\(ans=F'(1)=\sum\limits_{i=1}^n\frac{(m-i)!}{m!}m^i\)

#include<cmath>
#include<iomanip>
#include<iostream>
using namespace std;
long double cal(int n,int m){long double s=0,t=1;for(int i=1;i<=n;++i)t=t*m/(m-i+1),s+=t;return s;}
int main()
{
    int t,o,n,m;
    for(cin>>t;t;--t)
    {
	cin>>o>>m>>n;
	if(!o) cout<<fixed<<setprecision(10)<<(m==1? n:(pow(m,n)-1)/(m-1))<<endl;
	else cout<<fixed<<setprecision(10)<<cal(n,m)<<endl;
    }
}
posted @ 2020-05-06 16:44  Shiina_Mashiro  阅读(96)  评论(0编辑  收藏  举报