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 |
牛人给瞧瞧,郁闷,兄弟是在没招了,程序还好读!#include<iostream> using namespace std; int m,stick[30],count,used[30]; int cmp(const void *a,const void *b) { return *(int*)a<*(int*)b?1:-1; } bool soval(int s,int side) { if(side==0) { count++; return true; } for(int i=s;i<m;i++) { if(used[i] || side<stick[i]) continue; if(soval(i+1,side-stick[i])) { used[i]=true; return true; } } return false; } int main() { int n,i,all,side; scanf("%d",&n); while(n--) { scanf("%d",&m); all=0; count=0; memset(used,false,sizeof(used)); for(i=0;i<m;i++) { scanf("%d",&stick[i]); all+=stick[i]; } side=all/4; if(side*4==all) { qsort(stick,m,sizeof(stick[0]),cmp); if(stick[0]>side) { printf("no\n"); } else { while(soval(0,side)); if(count==4) { printf("yes\n"); } else { printf("no\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