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

神马整数拆分,dfs就能水过

Posted by javvy at 2012-02-27 00:51:51 on Problem 1664
#include <stdio.h>
int m,n;
int ans;
void dfs(int left,int index,int min)
{
	if(index==n)
	{
		if(left==0)
			ans++;
		return;
	}
	for(int i=min;i<=left;i++)
		dfs(left-i,index+1,i);
}

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		ans=0;
		scanf("%d %d",&m,&n);
		dfs(m,0,0);
		printf("%d\n",ans);
	}
}

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