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

容斥原理

Posted by ysjjovo at 2011-03-14 13:13:06 on Problem 2346
In Reply To:brute force Posted by:ysjjovo at 2011-03-13 21:01:52
#include<iostream>
using namespace std;
int cnt[6];

__int64 c(__int64 n,__int64 m){
	if(n==0)return 1;
	__int64 mul=1;
	for(int i=1;i<=m;i++,n--)mul=mul*n/i;
	return mul;
}
int main(){
	fill(cnt,cnt+6,2);//0,max
	int n;
	while(cin>>n){
		if(n&1)cout<<0;
		else{
			n/=2;
			if(cnt[n]>2)cout<<cnt[n];
			else{
				int s,i;
				for(s=1;s<n*9;s++){
					__int64 sum=0;
					for(i=0;i<=n;i++){
						if(s<10*i)break;
						__int64 t=c(n,i)*c(s-10*i+n-1,s-10*i);
						if(i&1)t=-t;
						sum+=t;
					}
					cnt[n]+=sum*sum;
				}
				cout<<cnt[n];
			}
		}
		cout<<endl;
	}
	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