请排序枚举满足以下条件的排列:
1、每个数都在1~m范围内;
2、同一个数不能出现超过2次。
输入
3 2
输出
1 1 2
1 2 1
1 2 2
2 1 1
2 1 2
2 2 1
我用排序写的,求指正
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,box[10005];
signed main(){
cin>>n>>m;
int cnt=0;
for(int i=1;i<=n;i++){
int a[15]={0};
for(int j=1;j<=m;j++){
if(a[j]<2){
box[++cnt]=j;
a[j]++;
}
}
}
int tmp=0;
for(int i=1;i<=cnt;i++){
tmp++;
cout<<box[i]<<" ";
if(tmp==n) cout<<"\n";
}
return 0;
}