比赛 20100420 评测结果 MMMMMMMM
题目名称 中奖的机率 最终得分 0
用户昵称 lc 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2010-04-20 10:13:21
显示代码纯文本
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<cstring>
using namespace std;
const int maxn = 22,maxm = 22,maxs = 1<<maxn;
int N,M;
double F[maxm][maxs];


void prep()
{
	scanf("%d%d",&N,&M);
}

double Power(int X,int Y)
{
	double Res = 1;
	for (int i=1; i<=Y; i++) Res *= X;
	return Res;
}

void work()
{
	if (M <N) {printf("0.0000\n"); return;}
	
	double P = Power(N,M);
	
	F[0][0] = 1/P;
	for (int i=0; i<M; i++)
		for (int j=0; j<1<<N; j++)
			if (F[i][j] >1e-50)
			{
				for (int k=0; k<N; k++)
					F[i+1][j | (1<<k)] += F[i][j];
			}
	printf("%.4lf\n",F[M][(1<<N)-1]);
}

int main()
{
	freopen("lottery.in","r",stdin);
	freopen("lottery.out","w",stdout);
	prep();
	work();
	return 0;
}