Ignatius and the Princess II of Writing Algorithms Every Day (Full Arrangement)

This topic mainly uses the function next_permutation
Nothing, the code is posted:

#include<iostream>
#include<cstdio>
#include<string.h>
#include<cmath>
#include<stdlib.h>
#include<fstream>
#include<algorithm>
using namespace std;

#define MAX  1010
int a[MAX];


int main(){
        int n ,m ;
        while(~scanf("%d%d",&n,&m))
        {
            for(int i = 0 ; i <n ; i++ )
            {
                a[i]=i+1;
            }
            for(int j = 1 ; j< m ;j++)
            {
                next_permutation(a,a+n);
            }
            printf("%d",a[0]);
            for(int i =1 ; i<n ; i++)
            {
                 printf(" %d",a[i]);
            }
            printf("\n");
        }
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325583724&siteId=291194637