Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

剪枝依据的啥原理?看不懂

Posted by 7days at 2010-05-03 02:03:19 on Problem 2248
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator