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

3731帮忙看看,谢了

Posted by volin at 2009-05-18 21:20:13
#include <iostream>
#include <cmath>
using namespace std;
/*
__int64 C(int n, int m)
{
	 __int64 sum = 1;
	 for(int i = 0; i < m; i++)
	 {
		sum = (sum * (n - i) / (i + 1)) % 100000007;
	 }
	 return sum;
}
*/
int main()
{
	 __int64 a[4][2001];
	 int X, Y, x, y;
	 int m, n, i, T;
	 __int64 sum;
	 cin >> T;
	 while(T--)
	 {
		  cin >> X >> Y >> x >> y;
		  int x1 = x;
		  int y1 = y;
		  int x2 = X - x;
		  int y2 = Y - y;

		  a[0][0] = 1;
		  a[1][0] = 1;
		  a[2][0] = 1;
		  a[3][0] = 1;

		  for(i = 1; i <= x1 - 1; i++)
		  {
				a[0][i] = (a[0][i-1] * (x1 - i) / i) % 100000007;
		  }

		  for(i = 1; i <= y1; i++)
		  {
				a[1][i] = (a[1][i-1] * (y1 - i + 1) / i) % 100000007;
		  }
		  for(i = 1; i <= x2; i++)
		  {
				a[2][i] = (a[2][i-1] * (x2 - i + 1) / i) % 100000007;
		  }
		  for(i = 1; i <= y2; i++)
		  {
				a[3][i] = (a[3][i-1] * (y2 - i + 1) / i) % 100000007;
		  }

		  n = x1 < x2 ? x1 : x2;
		  m = y1 < y2 ? y1 : y2;
		  n = n < m ? n : m;
		  if(x == 0 && y == 0)
			sum = 1;
		  else
		  {
			   sum = 1 + y2 + y2 * x2;
			   if(n)
			   {
					for(i = 1; i < n; i++)
					{
						 sum = (sum + ((a[3][i] * a[2][i]) % 100000007) * ((a[1][i] * a[0][i - 1]) % 100000007)) % 100000007;
						 sum = (sum + ((a[3][i] * a[2][i]) % 100000007) * ((a[1][i] * a[0][i]) % 100000007)) % 100000007;
						 sum = (sum + ((a[3][i + 1] * a[2][i]) % 100000007) * ((a[1][i] * a[0][i]) % 100000007)) % 100000007;
						 sum = (sum + ((a[3][i + 1] * a[2][i + 1]) % 100000007) * ((a[1][i] * a[0][i]) % 100000007)) % 100000007;
					}

					sum = (sum + ((a[3][i] * a[2][i]) % 100000007) * ((a[1][i] * a[0][i - 1]) % 100000007)) % 100000007;
					if(x1 - i > 0)
					{
						 sum = (sum + ((a[3][i] * a[2][i]) % 100000007) * ((a[1][i] * a[0][i]) % 100000007)) % 100000007;
						 if(y2 - i > 0)
						 {
							  sum = (sum + ((a[3][i + 1] * a[2][i]) % 100000007) * ((a[1][i] * a[0][i]) % 100000007)) % 100000007;
							  if(x2 - i > 0)
							  {
									sum = (sum + ((a[3][i + 1] * a[2][i + 1]) % 100000007) * ((a[1][i] * a[0][i]) % 100000007)) % 100000007;
							  }
						 }
					}
			   }
		  }
		  printf("%I64d\n", sum);
	 }
	 return 0;
}

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