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 |
这样写为什么WA,谁能给出有数据测试一下#include <iostream> using namespace std; #include <algorithm> int n,m,sum,stick[22],l; bool flag,used[22]; bool judge(int cur,int s) { if(cur==l) return true; else {for(int i=s+1;i<m;i++) { if(!used[i]&&cur+stick[i]<=l) { used[i]=true; if(judge(cur+stick[i],i)) return true; used[i]=false; } } } return false; } bool cmp(int a,int b) { return a>b;} int main() { int i,j; scanf("%d",&n); while(n--) { scanf("%d",&m); flag=sum=0; memset(stick,0,sizeof(stick)); memset(used,false,sizeof(used)); for(i=0;i<m;i++) { scanf("%d",stick+i); sum+=stick[i]; } sort(stick,stick+m,cmp); if(sum%4==0) { l=sum/4; //if(stick[0]>l) goto end; for(j=0;j<4;j++) if(!judge(0,0)) goto end; flag=true; } end: printf(flag?"yes\n":"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