algorithm里面有一个next_permutation(a,a+n);
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int maxn=10010; int n,m; int a[maxn]; int main() { scanf("%d%d",&n,&m); for(int i=0;i<n;i++) scanf("%d",&a[i]); while(m--) next_permutation(a,a+n); for(int i=0;i<n;i++) printf("%d ",a[i]); return 0; }