[STL] [全排列] [next_permutation] [洛谷] P1088 火星人

枚举T次下一个排列

有STL就很好写

但是没有STL岂不是凉凉

#include <iostream>
#include <algorithm>
using namespace std;

const int MAXN = 1e4 + 10;

int arr[MAXN];

int main()
{
    int n;

    cin>>n;

    int t;

    cin>>t;

    for(int i = 0; i < n; i++)
        cin>>arr[i];

    while(t--)
    {
        next_permutation(arr, arr + n);
    }

    for(int i = 0; i < n; i++)
        cout<<arr[i]<<' ';

    cout<<endl;

    return 0;
}

猜你喜欢

转载自blog.csdn.net/Zeolim/article/details/81313039