rt,这是我的代码:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<bitset>
using namespace std;
int n=0,llen;
int a[66];
bitset<66> used;
bool dfs(const int &len,const int &now,const int &usedcnt)
{
if(usedcnt==n) return 1;
for(register int i=now; i<=n; ++i)
{
if(used[i] || (i!=1 && !used[i-1] && a[i-1]==a[i])) continue;
used[i]=1;
if(len+a[i]<llen && dfs(len+a[i],i+1,usedcnt+1)) return 1;
else if(len+a[i]==llen && dfs(0,1,usedcnt+1)) return 1;
used[i]=0;
if(!len || len+a[i]==llen) return 0;
}
return 0;
}
inline int max(int a,int b) { return a>b?a:b; }
int main()
{
int N;
scanf("%d",&N);
int x=0,ax=0,sum=0;
for(register int i=1; i<=N; ++i)
{
scanf("%d",&x);
if(x<=50)
{
a[++n]=x;
ax=max(ax,a[n]);
sum+=a[n];
}
}
sort(a+1,a+n+1,greater<int>());
for(llen=ax; llen<=sum/2; ++llen)
{
used.reset();
if(sum%llen==0 && dfs(0,1,0))
{
printf("%d",llen);
return 0;
}
}
printf("%d",sum);
return 0;
}
在第 27 行为什么判断当拼成一个木棒后接下来无法实现,就直接 return 0
就是说第二个表达式为什么加上不会 WA
帮助我的人我会给一个关注作为回报 /kel