90分求助!!!
  • 板块P1164 小A点菜
  • 楼主livexcy
  • 当前回复2
  • 已保存回复2
  • 发布时间2023/7/24 21:04
  • 上次更新2023/11/3 07:50:19
查看原帖
90分求助!!!
943096
livexcy楼主2023/7/24 21:04
#include<bits/stdc++.h>
using namespace std;
int n, m, ans[105], sum=0, w[105], t=0;
void d(int x)
{
	if(x>n)
	{
		if(sum==m)
			t++;
		return ;
	}
	if(sum+w[x]<=m)
	{
		ans[x]=1;
		sum+=w[x];
		d(x+1);
		ans[x]=0;
		sum-=w[x];
		d(x+1);
	}
	else
	{
		ans[x]=0;
		d(x+1);
	}
}
int main()
{
	cin>>n>>m;
	for(int i=1; i<=n; i++)
		cin>>w[i];
	d(1);
	cout<<t;
	return 0;
}
2023/7/24 21:04
加载中...