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

Re:brute force

Posted by ysjjovo at 2011-03-13 21:40:12 on Problem 2346
In Reply To:brute force Posted by:ysjjovo at 2011-03-13 21:01:52
> #include<iostream>
> using namespace std;
> int ans,curCnt;
> int curNumber;
> int cnt;
> void work(int k,int cur){//k<=cnt-1,cur<=curNumber
> 	if(k==cnt-1){
> 		if(curNumber>=cur&&curNumber<=cur+9)curCnt++;// ÕâÒ»¾äshit!!!
> 	}
> 	else{
> 		if(cur+(cnt-k)*9<curNumber)return;
> 		int i;
> 		for(i=0;i<10;i++){
> 			if(cur+i>curNumber)return;
> 			work(k+1,cur+i);
> 		}
> 	}
> }
> 
> int main(){
> 	int n;
> 	cin>>n;
> 	if(n&1){
> 		cout<<0<<endl;
> 		return 0;
> 	}
> 	ans=2;
> 	int i;
> 	cnt=n/2;
> 	for(i=1;i<cnt*9;i++){
> 		curNumber=i;
> 		curCnt=0;//0,max
> 		work(0,0);
> 		ans+=(curCnt*curCnt);
> 	}
> 	cout<<ans<<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