#27784: C++


d10831523@gapps.fg.tp.edu.tw (廖與僑)

學校 : 臺北市立第一女子高級中學
編號 : 107948
來源 : [211.75.180.175]
最後登入時間 :
2022-10-03 21:31:01
d375. 10364 - Square -- UVa10364 | From: [203.64.52.40] | 發表日期 : 2021-10-29 20:48

#include<bits/stdc++.h>

using namespace std;

int m,a[20],x,u;

bool v[20]={false},o=false;

 

bool cmp(int a,int b){return a>b;

}

 

void dfs(int n,int i,int s){

if(o)return;

if(n==4&&u==m){

o=true;

cout<<"yes\n";

return;

}

if(s==x)dfs(n+1,0,0);

for(;i<m;i++)if(!v[i]){

if(s+a[i]<=x)v[i]=true,u++,dfs(n,i+1,s+a[i]),v[i]=false,u--;

dfs(n,i+1,s);

break;

}

}

 

int main(){

int t;cin>>t;

while(t--){

cin>>m;x=0;

for(int i=0;i<m;i++)cin>>a[i],x+=a[i];

if(m<4)cout<<"no\n";

else if(x%4)cout<<"no\n";

else{

o=false;

u=0;

sort(a,a+m,cmp);

x/=4;

dfs(0,0,0);

if(!o)cout<<"no\n";

}

 

}

}

 
ZeroJudge Forum