c ++ full array

First, the concept

  From any of n different elements taken m (m≤n) elements, lined up in a certain order, called a permutation of m elements taken from n different elements. When m = n all the arrangement of the whole arrangement is called. If this group has a number of n, then the number of full-arranged n! Months.

  For example a, b, c full array of a total of three! = 6 kinds are {a, b, c}, {a, c, b}, {b, a, c}, {b, c, a}, {c, a, b}, {c, b, a}.

Second, common operations

  1. header file

#include <algorithm>

  2. Use

  

  The arrangement next_permutation (arr, arr + n); arr If the absence of an arrangement, it returns 0, otherwise the return of 1, and updates the array

  Arrayed prev_permutation (arr, arr + n): Similarly .......

. Function: bool type return value, when a sequence is not present in the current arrangement, the function returns false, otherwise it returns true, the arranged number stored in an array

Note: You need to be arranged in ascending order of the array before use, or can only find out after several full array of the sequence.
    For example, if the array is initialized to 2,3,1 num, then the output becomes: {231} {312} {321}

Guess you like

Origin www.cnblogs.com/Accepting/p/11222799.html