标签:
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 419 Accepted Submission(s): 286
#include<cstdio> int a[22],b[22],ans[22]; int main(){ int t,i,j,tt,temp,ss,pos,n; scanf("%d",&t); while(t--){ scanf("%d",&n); int sum=0; for(i=0;i<n;i++){ scanf("%d",a+i); ans[i]=0; sum+=a[i]; } sum>>=1; int x=(1<<n); for(i=0;i<x;i++){//二进制枚举 tt=0;temp=i;pos=0;ss=0; while(temp){ if(temp&1){ b[tt++]=pos;//记录该团体每个成员在数组a中的位置 ss+=a[pos];//记录总票数 } temp>>=1; pos++; } if(ss>sum){ for(j=0;j<tt;j++) if(ss-a[b[j]]<=sum) ans[b[j]]++; } } for(i=0;i<n-1;i++) printf("%d ",ans[i]); printf("%d\n",ans[n-1]); } return 0; }
标签:
原文地址:http://www.cnblogs.com/wabi87547568/p/4688144.html