1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std;
bool used[25]; int d[25],n,side;
int cmp(int a,int b) { return a>b; }
bool dfs(int begin,int num,int len) { if(len==side&#==n) return 1; if(len==side) len=0; for(int i=begin;i<n;i++) { if(i&&d;[i]==d[i-1]&&used;[i-1]==0) continue; if(d[i]<side-len&&used;[i]==0) { used[i]=1; if(dfs(i+1,num+1,len+d[i])) return 1; used[i]=0; } if(d[i]==side-len&&used;[i]==0) { used[i]=1; if(dfs(0,num+1,len+d[i])) return 1; used[i]=0; } } return 0; }
int main() { int t,sum; scanf("%d",&t;); while(t--) { sum=0; scanf("%d",&n;);; for(int i=0;i<n;i++) { scanf("%d",&d;[i]); sum+=d[i]; } if(sum%4) { printf("non"); continue; } side=sum/4; sort(d,d+n,cmp); memset(used,0,sizeof(used)); if(dfs(0,0,0)) printf("yesn"); else printf("non"); } }
|