百练 4004 数字组合

# include 
# include 
# include 
int NUM = 0;
int SUM = 0;
int a[100];
int t;
void sum(int *a,int m,int n)
{
	if(m <= 0 || n <= 0)
		return;
	int i;
	for(i = n - 1;i >= 0;i--)
	{
		SUM += a[i];
		if(SUM == t)
			NUM++;
		else 
			if(m > 1)
			{
				sum(a,m-1,i);
			} 
			SUM -= a[i];
	}
}
void main()
{
	int i,n;
	scanf("%d %d",&n,&t);
	NUM = 0;
	for(i = 0;i < n;i++)
		scanf("%d",&a[i]);
	sum(a,n,n);
	printf("%d\n",NUM);
}

你可能感兴趣的:(百练 4004 数字组合)