学习笔记:
https://blog.csdn.net/a358463121/article/details/45543879
https://blog.csdn.net/MsStrbig/article/details/79823555
例题hdu1027
全排列函数用法https://blog.csdn.net/HowardEmily/article/details/68064377
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int SIZE=1002;
int main()
{
int n,m;
int i,count;
int seq[SIZE];
while(scanf("%d %d",&n,&m)!=EOF)
{
for(i=0;i<SIZE;i++)
seq[i]=i+1;
count=0;
do
{
count++;
if(count==m)
{
for(i=0;i<n;i++){
if(i==n-1)
cout<<seq[i];
else
cout<<seq[i]<<" ";}
cout<<endl;
break;
}
}
while (next_permutation(seq,seq+n));
}
return 0;
}
hdu1716,排列2
依旧用全排列函数,麻烦的就是把输出格式搞对
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a[4],c=0;
while(~scanf("%d%d%d%d",&a[0],&a[1],&a[2],&a[3]))
{
if(a[0]==0&&a[1]==0&&a[2]==0&&a[3]==0)
break;
sort(a,a+4);
if(c) printf("\n");
c=1;
int flag=1,tmp;
do{
if(a[0]==0)
continue;
if(flag){
printf("%d%d%d%d",a[0],a[1],a[2],a[3]);
flag=0;}
else if(tmp==a[0])
printf(" %d%d%d%d",a[0],a[1],a[2],a[3]);
else
printf("\n%d%d%d%d",a[0],a[1],a[2],a[3]);
tmp=a[0];
}while(next_permutation(a,a+4));
printf("\n");
}
return 0;
}