Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

终于过了……huuuuuuuuuuuuuuu!

Posted by frkstyc at 2005-04-02 15:48:42 on Problem 1322
谁能告诉我母函数法怎么就用不了呢?
liurujia书上的式子居然是不对的,死活又重算了一条,和ac程序很多答案都相同啊

double binomial(int n, int k)
{
	double N[100], K[100];
	int nt = 0, kt = 0;
	double t = 1.0;
	int i;
	if(n == 0)
	{
		return 1.0;
	}
	if(k > n / 2)
	{
		k = n - k;
	}
	for(i = 0; i < 100; i++)
	{
		N[i] = 1.0;
		K[i] = 1.0;
	}
	for(i = n; i > n - k; i--)
	{
		double t = N[nt] * i;
		if(t <= 1099511627776.0)
		{
			N[nt] = t;
		}
		else
		{
			nt++;
			N[nt] = i;
		}
	}
	for(i = k; i > 1; i--)
	{
		double t = K[kt] * i;
		if(t <= 1099511627776.0)
		{
			K[kt] = t;
		}
		else
		{
			kt++;
			K[kt] = i;
		}
	}
	for(i = 0; i <= kt; i++)
	{
		N[i] /= K[i];
	}
	for(i = 0; i <= nt; i++)
	{
		t *= N[i];
	}
	return t;	
}

double solve(int c, int m, int n)
{
	double a[202] = {0.0}, p = 0.0;
	int i, k;
	if(m > c || m > n || ((m ^ n) & 1) != 0)
	{
		return 0.0;
	}
	for(k = c; k >= 0; k--)
	{
		for(i = max(0, k + m - c); i <= min(m, k); i++)
		{
			a[2 * k - c + c] += pow(-1.0, m - i) * binomial(c - m, k - i) * binomial(m, i);
		}
	}
	for(k = -c; k <= c; k++)
	{
		p += a[k + c] * pow((double)k / c, n);
	}
	p *= pow(2, -c) * binomial(c, m);
	return p;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator