Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int a=9<<9e9;
- struct S{ int rank; int value; S **list; };
- S *max(int x){
- S *s=new S();s->rank=x;s->value=a;
- if(x==0){s->list=0;return s;}
- s->list=new S *[a+1];
- for(int i=0;i<a;++i){s->list[i]=max(x-1);}s->list[a]=0;
- return s;
- }
- S *dup(S *s)
- {
- if(s==0)return s;
- S *x=new S();
- x->rank=s->rank;x->value=s->value;
- if(s->list==0){x->list=s->list;return x;}
- int i=0;
- while(s->list[i])++i;
- x->list=new S *[i+1];
- while(i>=0){x->list[i]=dup(s->list[i]);--i;}
- return x;
- }
- bool next(S *s){
- if(s==0)return true;
- if(s->rank==0) return (--s->value)!=0;
- int i=0;
- while(!next(s->list[i])){s->list[i]=max(s->list[i]->rank);++i;}
- if(!s->list[i])return (--s->value)!=0;
- return true;
- }
- void f(S *s){
- a++;
- if(!next(s))return;
- S *t=max(a);
- while(next(t))f(dup(s));
- }
- int main()
- {
- f(max(a));
- return a;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement