Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void Xdrzewo(int n, int t, int T[], int TAG[], int MAX[], int X[]);
- void out(int tab[], int n);
- void One2subset(int one, int SET[], int left, int right);
- int main()
- {
- //GENEROWANIE X-sekwencji 010101010101
- int n,t;
- cout<<"Prosze podac liczbe wierzcholkow wewnetrznych n: ";
- cin>> n;
- cout<<"Prosze podac liczbe potomkow t: ";
- cin>> t;
- int *T=new int[n+1];
- int *TAG=new int[n+1];
- int *MAX=new int[n+1];
- int *X=new int[n*t+1];
- Xdrzewo(n,t,T,TAG,MAX,X);
- //system ("pause");
- return 0;
- delete [] T;
- delete [] TAG;
- delete [] MAX;
- delete [] X;
- }
- void Xdrzewo(int n, int t, int T[], int TAG[], int MAX[], int X[])
- {
- int ind=1;
- int s=1;
- for(int i=1; i<=n;i++)
- {
- MAX[i]=(i-1)*(t-1)+1;
- }
- One2subset(s,T,ind,n);
- One2subset(0,TAG,ind,n);
- One2subset(1,X,ind,n);
- One2subset(0,X,n+1,n*t);
- out(X,n*t);
- ind=n;
- while(ind>1)
- {
- if(T[ind]<MAX[ind])
- {
- s=T[ind]+1;
- One2subset(s,T,ind,n);
- One2subset(0,X,T[ind-1]+ind-1,n*t);
- One2subset(1,X,T[ind]+ind-1,T[ind]+n-1);
- if(s==MAX[ind]) One2subset(1,TAG,ind,ind);
- if(ind<n) One2subset(0,TAG,ind+1,n);
- out(X,n*t);
- ind=n;
- }
- else
- {
- ind--;
- }
- }
- }
- void out(int tab[], int n){
- for(int i=1;i<=n;i++)
- {
- cout<<tab[i]<<" ";
- }
- cout<<endl;
- }
- void One2subset(int one,int SET[],int left,int right)
- {
- for(int i=left;i<=right;i++)
- {
- SET[i]=one;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement