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 |
Re:谁能告诉我怎么样除去重复的In Reply To:谁能告诉我怎么样除去重复的 Posted by:6233843 at 2006-07-17 18:13:52 int ans[12],n,k,data[12],f; void search(int i,int s){ int j; if(!s){ for(f=j=1,printf("%d",ans[0]);j<k;j++)printf("+%d",ans[j]); printf("\n"); return; } if(i>=n||s<0)return; for(j=i;j<n;j++)if(j==i||data[j]!=data[j-1]){//这里的处理避免了重复的情况:data[j]!=data[j-1]) ans[k++]=data[j]; search(j+1,s-data[j]); k--; } } void main(){ int j,t; while(scanf("%d%d",&t,&n),t){ f=k=0; for(j=0;j<n;j++)scanf("%d",&data[j]); printf("Sums of %d:\n",t); search(0,t); if(!f)printf("NONE\n"); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator