topic
Thinking
How much each take, finally need to reach a fixed value, it is easier to think of the above generation function
For a color
If this color is selected odd number
\(F(x)=\sum_{i=0}^{\infty}x^{2*i+1}\)
If it is an even number
\(G(x)=\sum_{i=0}^{\infty}x^{2i}\)
But the problem is that if you roll up their
Because the issue of the order
The answer is not coefficient of an item.
We actually have to roll up should be
If it is an odd number
\(F(x)=\sum_{i=0}^{\infty}\frac{x^{2i+1}}{(2i+1)!}\)
If it is an even number
\(G(x)=\sum_{i=0}^{\infty}\frac{x^{2i}}{(2i)!}\)
After the rolled-up \ (x ^ n \) coefficient is the answer
Then we consider how \ (F \) and \ (G \) converted into a closed form
We first consider the simplest form,
\(A(x)=\sum_{i=0}^{\infty}\frac{x^i}{i!}\)
Is not that \ (the X-E ^ \) ?
Explain the reasons
We set \ (B (x) = e ^ x \)
Of \ (B \) Taylor expansion
\(B(x)=\sum_{i=0}^{\infty}(\frac{B^{'(i个)}(x_0)}{i!}*(x-x_0)^i)\)
We take \ (x_0 = 0 \)
\(B(x)=\sum_{i=0}^{\infty}(\frac{B^{'(i个)}(0)}{i!}*(x-x_0)^i)\)
Due to the nature of the e
\(B'=B\)
and so
\(B(x)=\sum_{i=0}^{\infty}\frac{x^i}{i!}=A(x)\)
We have this thing, let us consider how to construct
If an odd number, in fact, there is no \ (X 2i ^ {} \) ,
Is the \ (F (x) = \ frac {e ^ xe ^ {- x}} {2} \)
For \ (G (x) \) is configured the same way
\(G(x)=\frac{e^x+e^{-x}}{2}\)
Desired is \ (F ^ m (x) * G ^ {cm} (x) \) a \ (x ^ n \) coefficients
Consider using the binomial theorem and vigorously expand
\(\begin{aligned}F^m(x)*G^{c-m}(x)&=(\frac{e^x-e^{-x}}{2})^m*(\frac{e^x+e^{-x}}{2})^{c-m}\\&=\frac{\sum_{k=0}^{m}(-1)^{k}C_{m}^{k}e^{(m-k)x}e^{-kx}}{2^m}*\frac{\sum_{k=0}^{c-m}C_{c-m}^{k}e^{(c-m-k)x}e^{-kx}}{2^{c-m}}\end{aligned}\)
The denominator can be directly used to quickly calculate power, we then molecular further simplification
It is
\(\sum_{i=0}^{m}\sum_{j=0}^{c-m}(-1)^iC_m^iC_{c-m}^je^{(c-2i-2j)x}\)
We then written in the form of e Generating Function
\(\sum_{i=0}^{m}\sum_{j=0}^{c-m}(-1)^iC_m^iC_{c-m}^j\sum_{k=0}^{\infty}\frac{(c-2i-2j)^k}{k!}\)
Because useful for us e in the form of merely generating function term coefficient n
and so
\(\sum_{n=0}^{\infty}\frac{\sum_{i=0}^{m}\sum_{j=0}^{c-m}(-1)^iC_m^iC_{c-m}^{j}(c-2i-2j)^n}{n!}x^n\)
Because of \ (n-! \) Itself is converted into the form of a master e function occurring, so \ (n-! \) Is negligible
But we ask for is a probability, and finally divide by a \ (the n-^ c \) ,
But also because we define the generating function of time itself did not consider those candies to choose an odd number, so you should choose a \ (C_c ^ m \)
Therefore, the final answer is \ (\ frac {C_c ^ m } {2 ^ cc ^ n} \ sum_ {i = 0} ^ {m} \ sum_ {j = 0} ^ {cm} (- 1) ^ iC_m ^ iC_ {cm} ^ j (c -2i-2j) ^ n \)
Analysis of this formula, we can get \ (m \ le c \)
Therefore, the overall time complexity is \ (O (c ^ 2 * logn) \)
Code
#include<iostream>
#include<cstdio>
using namespace std;
double ans;
long long c,m,n;
double qkpow(long long a,long long b)
{
if(b==0)
return 1;
if(b==1)
return a;
double t=qkpow(a,b/2);
t=t*t;
if(b%2==1)
t=t*a;
return t;
}
double C(long long n,long long m)
{
double ret=1;
for(int i=n;i>=n-m+1;i--)
{
ret=ret*i/(n-i+1);
}
return ret;
}
int main()
{
while(cin>>c)
{
if(!c)
break;
ans=0;
cin>>n>>m;
if(m>c||m>n||(n-m)%2==1)
{
printf("0.000\n");
continue;
}
for(int i=0;i<=m;i++)
{
for(int j=0;j<=c-m;j++)
{
ans+=qkpow(-1,i)*C(m,i)*C(c-m,j)*qkpow(c-2*i-2*j,n);
}
}
ans=ans*C(c,m)/qkpow(2,c)/qkpow(c,n);
printf("%.3lf\n",ans);
}
return 0;
}