Determinant (ii): Total and reverse order number

Source: Internet
Author: User

By the definition of the N-order determinant, it is necessary to solve the whole permutation and reverse order number of a sequence first.

1. Full arrangement

Any element of M (m≤n) from n different elements, arranged in a certain order, is called an arrangement of extracting m elements from n different elements. All permutations are called when m=n.

    • Algorithm principle

1. Suppose there is a sequence {1,2,3,4,5} that first arranges the first element, a total of 5 cases

{1,*,*,*,*}

{2,*,*,*,*}

{3,*,*,*,*}

{4,*,*,*,*}

{5,*,*,*,*}

2. Separate analysis 1. In the first case, arrange the second element with a total of four cases

{1,2,*,*,*}

{1,3,*,*,*}

{1,4,*,*,*}

{1,5,*,*,*}

3. With this push class, the third, four, and five elements are arranged in turn. You can get the full array of sequences

    • Vb. NET Customization Methods

1. Method Name: Getfullperm (ByVal numarray () As Integer, ByVal leftindex As Integer, ByRef Result as List (of Array))

2. Function: Pass in a one-dimensional array and list (of array), to obtain the full array of the one-dimensional arrays

3. Parameters:

Numarray: A one-dimensional array that requires a fully arranged sequence

Leftnum: The currently solved index, which is passed in 0 when the method is called

Result:list (of Array), used to hold the results of the full arrangement

    Private SubGetfullperm (ByValNumarray () as Integer,ByValLeftindex as Integer,ByRefResult asList ( ofArray)) DimTemp as Integer        IfLeftindex = Numarray.length-1  Then            DimTemparray (Numarray.length-1) as IntegerNumarray.copyto (Temparray,0) Result.add (temparray)ElseTemp=Numarray (Leftindex) fori = Leftindex toNumarray.length-1Numarray (Leftindex)=Numarray (i) Numarray (i)= Temp'SwapGetfullperm (Numarray, Leftindex +1, Result) Numarray (i)=Numarray (Leftindex) Numarray (leftindex)= Temp'Restore Swap            Next        End If    End Sub

2. Number of reverse order

In one arrangement, if the front and back positions of a pair of numbers are opposite to the size order, that is, the previous number is greater than the subsequent number, then they are called an inverse. The total number of reverse order in an arrangement is called the number of reverse order

    • Algorithm principle

1. Suppose there is a sequence {3,1,2,4,5} that first asks for the number of reverse order of the first element, t1=0

2. Solve the second, three, four and five position of the inverse number of the elements in sequence, t2=1,t3=1,t4=0,t5=0

3. The sum of the reverse number of each position element is obtained, t=t1+t2+t3+t4+t5=2

    • Vb. NET Custom Functions

1. Function name: Getinversenum (ByVal Numarray () as Integer)

2. Function: Pass in a one-dimensional array to find the inverse number of the one-dimensional array sequence

3. Parameters:

Numarray: A one-dimensional array that requires a sequence of inverse numbers

    Private FunctionGetinversenum (ByValNumarray () as Integer)        DimNum as Integer=0         fori =0  toNumarray.length-1             forj = I toNumarray.length-1                IfNumarray (i) > Numarray (j) ThenNum + =1            Next        Next        ReturnNumEnd Function

Determinant (ii): Total and reverse order number

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.