全WA求助
查看原帖
全WA求助
826774
Little_Fox_Fairy楼主2023/7/13 19:16

这是代码

#include<bits/stdc++.h>
using namespace std;
int n,l,r,ans;
int w[41],f[41],k[41];
void dfs(int step,int tot,int start)
{
    if (tot>=l&&tot<=r) 
      ans++;
	for (int i=start;i<=n;i++)
	  if (!f[i])
	  {
	  	tot+=w[i];
	  	f[i]=1;
	  	if (tot>=l&&tot<=r)
	  	  ans++;
	  	else
	  	  dfs(step+1,tot,i+1);
	  	tot-=w[i];
	  	f[i]=0;
	  }
	return ;
}
int main()
{
	ios::sync_with_stdio(0);
	cin>>n>>l>>r;
	for (int i=1;i<=n;i++)
	  cin>>w[i];
	dfs(1,0,1);
	cout<<ans;
	return 0;
}

为什么会WA啊······

2023/7/13 19:16
加载中...