Description
用
m
个不同的数字去放到一个
Input
三个整数 n,m,k(1≤n≤300,n2≤m≤105,n≤k≤m)
Output
输出得分期望值与 1099 的较小值
Sample Input
1 2 1
Sample Output
2.5
Solution
一状态
sta
被标记行列数和为
f(sta)
,则其对分数总和贡献为
2f(sta)
,而注意到
2f(sta)
为从这些行列集中选出一子集方案数,设状态集为
S
,则得分期望值
其中
pr,c
为选出的
r
行
Code
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int>P;
const int INF=0x3f3f3f3f,maxn=100005;
ld f[maxn];
ld C(int n,int m)
{
return f[n]-f[m]-f[n-m];
}
int main()
{
f[0]=0;
for(int i=1;i<=1e5;i++)f[i]=f[i-1]+log(1.0*i);
int n,m,k;
scanf("%d%d%d",&n,&m,&k);
ld ans=0;
for(int x=0;x<=n;x++)
for(int y=0;y<=n;y++)
if(n*(x+y)-x*y<=k)
{
int z=n*(x+y)-x*y;
ld temp=C(n,x)+C(n,y)+C(m-z,k-z)-C(m,k);
ans=min((ld)1e99,ans+exp(temp));
}
printf("%.10f\n",(double)ans);
return 0;
}