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 chenxuan123456789 at 2012-07-29 08:55:39 on Problem 1664
#include "stdio.h"
int n,m,a[12],sum;
void dfs(int deep,int total)
{
	int i;
	if(deep>m+1)
	return;
	if(total==n&&deep==m+1)
	{
		sum++;
	 	return;
	}
	for(i=0;i<=n;i++)
	{
		a[deep]=i;
		if(a[deep]>=a[deep-1])
		dfs(deep+1,total+a[deep]);
	}
}
int main()
{
	int cases;
	scanf("%d",&cases);
    while(cases--)
    {
    	scanf("%d %d",&n,&m);
    	sum=0;
    	dfs(1,0);
    	printf("%d\n",sum);
     }
    return 1;
}

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