HDU 1518 Square
解题思路:sum%4!=0 , max<sum/4
#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm>usingnamespace std;int a[100];bool vis[100],flag;int m,ave;bool dfs(int ans,int sum,int cnt){ if(sum==ave)returntrue; for(int i=cnt;i<m;i++){ if(a[i]==a[i-1]&&!vis[i-1])continue; if(!vis[i]&&a[i]<=ans){//shit !!! < vis[i]=true; if(a[i]==ans){ if(dfs(ave,sum-a[i],0)) returntrue; } elseif(dfs(ans-a[i],sum-a[i],i)) returntrue; vis[i]=false; if(ans==ave)returnfalse; } } returnfalse;}int main(){ int n,sum; scanf("%d",&n); while(n--){ scanf("%d",&m); sum=0; for(int i=0;i<m;i++){ scanf("%d",&a[i]); sum+=a[i]; } sort(a,a+m); flag=false; ave=sum/4; if(a[m-1]>ave||sum%4!=0){ cout<<"no"<<endl; continue; } else{ memset(vis,false,sizeof(vis)); if(dfs(ave,sum,0)) flag=true; } if(flag) cout<<"yes"<<endl; else cout<<"no"<<endl; } return0;}