Expand Expand Cantor & Cantor inverse study notes

what. . . Long time no write. . . It may be the last one, right study notes

Title effect: seeking the given sequence position in the whole arrangement of a given rankings from && arrangement.

This is the inverse Cantor Cantor launched && expanded wanted to do things. The following introduced in turn

First, Cantor Expand

First, we know what it is doing.

It is given to a sequence among the full array, seeking its ranking throughout the whole arrangement.

Equation is given:
! K = \ sum_. 1} ^ {n-I = (Ni) \ sum_ {J} = ^ n-I +. 1 (A_ {K, I}> {K A_, J})

Explain: Consider this bit i sequence for this sequence, only the first i bits are less than or equal it, it must be smaller than the i-th bit of all sequences will be in front of it, so for every combination of consideration, is the result a.

Pieces of code:

LL KTZ (LL * A) 
{ 
    LL ANS = 0 ;
     for (LL I = . 1 ; I <= n-; I ++ ) 
    { 
        LL CNT = 0 ;
         for (LL J = I + . 1 ; J <= n-; J ++ ) 
        { 
            IF (a [I]> a [J]) // for every considered 
            CNT ++ ; 
        } 
        ANS + CNT * FAC = [N- I]; 
    } 
    return ANS + . 1 ; // required because the former number, All rankings +1 
}

Second, the reverse Cantor Expand

Well, that has been seeking an array of rank how it?

Cantor launched by the availability, to get each and every array, it is necessary to determine how much larger than the front of it.

So, in turn, to every consideration can be made much larger than it is, which is seeking the above formula brackets stuff, then bit by bit reduction, became the original sequence

Process: First, supra, -1

Then each one, divided by the number corresponding to the fac, not used to determine a number, as the current answer to

Pieces of code:

ll nkt(ll k)
{
    k-=1;
    ll j; 
    memset(vis,0,sizeof(vis));
    for(ll i=1;i<=n;i++)
    {
        ll s=k/fac[n-i];
        for(j=1;j<=n;j++)
        {
            if(!vis[j])
            {
                if(!s)
                break;
                s--;
            }
        }
        printf("%d ",j);
        vis[j]=1;
        k%=fac[n-i];
    }
    printf("\n");
}

(Finish)

Guess you like

Origin www.cnblogs.com/ajmddzp/p/11701540.html