hdu 1518 深搜
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; int len[22],n,El; int vi[22]; int dfs(int k,int pos,int nowlen) { int i,j; if(nowlen==El) { if(k==n) return 1; else nowlen=0,pos=0; } for(i=pos;i<n;i++) { if(!vi[i]&&nowlen+len[i]<=El) { vi[i]=1; if(dfs(k+1,i+1,nowlen+len[i])) return 1; vi[i]=0; } } return 0; } int main() { int t,i,j,Max,sum=0;; scanf("%d",&t); while(t--) { scanf("%d",&n); Max=0,sum=0; memset(vi,0,sizeof(vi)); for(i=0;i<n;i++) { scanf("%d",&len[i]); if(len[i]>Max) Max=len[i]; sum+=len[i]; } El=sum/4; if(El*4!=sum||Max>El) { printf("no\n"); continue; } if(dfs(0,0,0)) printf("yes\n"); else printf("no\n"); } return 0; }