Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
ac了好爽啊!#include <stdio.h> #include <string.h> #include <stdlib.h> int n,num[30],len,f,flag[30]; int cmp(const void *_a,const void *_b) { int *a=(int*)_a; int *b=(int*)_b; return *b-*a; } void dfs(int l,int s,int d) { int i; if(d==3) { f=1; return; } if(l==0) dfs(len,0,d+1); for(i=s;i<n;i++) { if(num[i]<=l&&!flag[i]) { flag[i]=1; dfs(l-num[i],i+1,d); flag[i]=0; while(i+1<n&&num[i]==num[i+1])i++; } } } int main() { int cases,i,sum; scanf("%d",&cases); while(cases--) { sum=0; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&num[i]); sum+=num[i]; } if(sum%4) { printf("no\n"); continue; } qsort(num,n,sizeof(num[0]),cmp); len=sum/4; f=0; memset(flag,0,sizeof(flag)); dfs(len,0,0); if(f) printf("yes\n"); else printf("no\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator