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:我的递归程序

Posted by cuiwj871128 at 2008-10-20 16:20:03 on Problem 1664
In Reply To:我的递归程序 Posted by:orangeman at 2008-08-22 23:02:51
> 基本思想就是把盘子中的苹果数目排序,把数目最大的那个盘子拿出来,剩下的进行递归。
> 这样 “3 4 0” 这种情况就不可能出现了。
> 
> #include <iostream>
> using namespace std;
> 
> int f(int i, int j, int maxVal)
> {
> 	int sum = 0;
> 	if( j==1 ) return 1;
> 	if( i==1 || i==0 ) return 1;
> 	int k;
> 	for( k=min(maxVal,i); k*j>=i; k--)//k值不能小于当前平均每个盘子中的苹果数
> 	{
> 		sum = sum + f(i-k, j-1, k);
> 	}
> 	return sum;
> }
> 
> int main()
> {
> 	int t, M, N;
> 	cin>>t;
> 	while(t--)
> 	{
> 		cin>>M>>N;
> 		cout<<f(M,N, M+1)<<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