P1088 Martian (Logu)

Original title portal

Insert picture description here
Insert picture description here
Idea: For water problems, use the next_permutation() method in STL to solve the full arrangement problem

Code reference

#include <bits/stdc++.h>
using namespace std;
int a[10001],n,m;
int main()
{
    
    
    cin>>n>>m;
    for(int i = 0;i < n;i++)
        cin>>a[i];
    for(int i = 0;i < m;i++)
        next_permutation(a,a+n);
    for(int i = 0;i < n;i++)
        cout<<a[i]<<" ";
    return 0;
}

Guess you like

Origin blog.csdn.net/Bertil/article/details/106818262