next_permutation 函数

Nannan Lv5

next_permutation 函数

next_permutation是全排列函数。

一、基本用法

1
2
3
4
int a[];
do{

}while(next_permutation(a,a+n));

二、例题

[P1088 [NOIP2004 普及组] 火星人]([P1088 NOIP2004 普及组] 火星人 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) )

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include<bits/stdc++.h>
using namespace std;
int n,m;
int a[10010];
int main()
{
cin>>n>>m;
for(int i = 1;i<=n;i++)cin>>a[i];

for(int i = 1;i<=m;i++)
{
next_permutation(a+1,a+1+n);
}
for(int i = 1;i<=n;i++)cout<<a[i]<<" ";

return 0;
}
  • Title: next_permutation 函数
  • Author: Nannan
  • Created at : 2023-07-09 12:30:00
  • Updated at : 2024-09-30 21:06:18
  • Link: https://redefine.ohevan.com/2023/07/09/next_permutation/
  • License: This work is licensed under CC BY-NC-SA 4.0.
Comments
On this page
next_permutation 函数