King_and_Grey @ 2024-06-02 07:54:30
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n,m,a[100000];
void Prn(){
for(int i = 1;i <= m;i++)
cout << a[i] << " ";
cout << endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; i++){
a[i] = i;
}
do{
Prn();
}while(next_permutation(a + 1, a + n + 1));
return 0;
}
错在哪?
by AfterFullStop @ 2024-06-02 08:21:43
假如说
初始时是 1 2 3 4 5 6 7 8 9 10
next_permutation
之后是 1 2 3 4 5 6 7 8 10 9
但是你两次输出的都是 1 2 3 4 5
于是你寄了。
不过你把排列哈希一下,确保你没有重复输出这样也可以对(
by nizixuan @ 2024-06-02 08:25:20
@greyandking 3 1就寄了,使用next_permutation是显然不行的
by King_and_Grey @ 2024-06-02 08:27:29
@AfterFullStop @nizixuan
谢谢!已关注