Title description:

An earthquake occurred in an area, the disaster area has been very difficult, the victims are in urgent need of some tents, clothing, food and blood plasma and other materials. Roads leading to the disaster area were covered in landslides, with more than 70 percent of the road surface damaged and Bridges destroyed. The state immediately activated the emergency plan, launched the largest non-combat air lift in history, ready to drop urgently needed supplies to the disaster area.

When one party is in trouble, eight parties help. Now we know that there are N places A1, A2,… An supplies are available for deployment. At present, the quantity of materials needed in the disaster area is M.

Now, please help me calculate how many material scheduling schemes there are. Assume that once a location is selected for deployment, all of its supplies are removed.

Input:

The first line: K indicates that there are K groups of test data.

Then there are 2 rows for each group of test data. The first row: N M, the second row: A1, A2…… An

Output:

For each set of test data, output one line: total options for material scheduling

Title description:

An earthquake occurred in an area, the disaster area has been very difficult, the victims are in urgent need of some tents, clothing, food and blood plasma and other materials. Roads leading to the disaster area were covered in landslides, with more than 70 percent of the road surface damaged and Bridges destroyed. The state immediately activated the emergency plan, launched the largest non-combat air lift in history, ready to drop urgently needed supplies to the disaster area.

When one party is in trouble, eight parties help. Now we know that there are N places A1, A2,… An supplies are available for deployment. At present, the quantity of materials needed in the disaster area is M.

Now, please help me calculate how many material scheduling schemes there are. Assume that once a location is selected for deployment, all of its supplies are removed.

Input:

The first line: K indicates that there are K groups of test data.

Then there are 2 rows for each group of test data. The first row: N M, the second row: A1, A2…… An

Output:

For each set of test data, output one line: total options for material scheduling

Example Input:

2 4 4 1 1 2 2 4 6 1 1 2 2 2 2

Sample output:

3

1

Program code:

#include<stdio.h>
#include<string.h>
int main(a)
{
	int t,i,j,m,n;
	int dp[1010],a[110];
	scanf("%d",&t);
	while(t--)
	{
		memset(dp,0.sizeof(dp));
		dp[0] =1;
		scanf("%d%d",&n,&m);
		for(i=1; i<=n; i++)scanf("%d",&a[i]);
		for(i=1; i<=n; i++)for(j=m; j>=a[i]; j--) dp[j]=dp[j]+dp[j-a[i]];printf("%d\n",dp[m]);
	}
	return 0;
}
#include<stdio.h>
#include<string.h>
void dfs(int s,int i);
int a[110],book[110],sum,m,n;
int main(a)
{
	int t,i; 
	scanf("%d",&t);
	while(t--)
	{
		sum=0;
		memset(a,0.sizeof(a));
		memset(book,0.sizeof(book));
		scanf("%d%d",&n,&m);
		for(i=1; i<=n; i++)scanf("%d",&a[i]);
		dfs(0.1);
		printf("%d\n",sum);
	}
	return 0;
}
void dfs(int s,int i)
{
	int j;
	if(s>m)
		return;
	if(s==m)
	{
		sum++;
		return;
	}
	for(j=i; j<=n; j++) {if(book[i]==0)
		{
			s+=a[j];
			book[j]=1;
			dfs(s,j+1);
			book[j]=0; s-=a[j]; }}}Copy the code

Title description:

 

An earthquake occurred in an area, the disaster area has been very difficult, the victims are in urgent need of some tents, clothing, food and blood plasma and other materials. Roads leading to the disaster area were covered in landslides, with more than 70 percent of the road surface damaged and Bridges destroyed. The state immediately activated the emergency plan, launched the largest non-combat air lift in history, ready to drop urgently needed supplies to the disaster area.

When one party is in trouble, eight parties help. Now we know that there are N places A1, A2,… An supplies are available for deployment. At present, the quantity of materials needed in the disaster area is M.

Now, please help me calculate how many material scheduling schemes there are. Assume that once a location is selected for deployment, all of its supplies are removed.

 

Input:

 

The first line: K indicates that there are K groups of test data.

Then there are 2 rows for each group of test data. The first row: N M, the second row: A1, A2…… An

 

Output:

 

For each set of test data, output one line: total options for material scheduling

Example Input:

2 4 4 1 1 2 2 4 6 1 1 2 2 2 2

Sample output:

3

1

Program code:

#include<stdio.h>
#include<string.h>
int main(a)
{
	int t,i,j,m,n;
	int dp[1010],a[110];
	scanf("%d",&t);
	while(t--)
	{
		memset(dp,0.sizeof(dp));
		dp[0] =1;
		scanf("%d%d",&n,&m);
		for(i=1; i<=n; i++)scanf("%d",&a[i]);
		for(i=1; i<=n; i++)for(j=m; j>=a[i]; j--) dp[j]=dp[j]+dp[j-a[i]];printf("%d\n",dp[m]);
	}
	return 0;
}
Copy the code