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 |
剪枝依据的啥原理?看不懂In Reply To:dfsid 0ms飘过。。。 Posted by:isnowfy at 2010-05-02 22:57:54 > #include<cstdio> > int mark,n,d,a[20],b[]={1,2,4,8,16,32,64,128,256,512,1024}; > void dfs(int i){ > if(i==d){ > if(a[i-1]==n) > mark=0; > return ; > } > if(a[i-1]*b[d-i]<n) > return ; > for(int j=0;j<i;j++) > if(mark){ > a[i]=a[i-1]+a[j]; > dfs(i+1); > } > } > int main(){ > a[0]=1; > a[1]=2; > while(scanf("%d",&n),n){ > if(n==1) > printf("1\n"); > else if(n==2) printf("1 2\n"); > else{ > mark=1; > d=2; > while(mark){ > d++; > dfs(2); > } > for(int i=0;i<d-1;i++) > printf("%d ",a[i]); > printf("%d\n",a[d-1]); > } > } > return 0; > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator