求助
查看原帖
求助
677581
_Glassy_Sky_楼主2023/7/19 21:03
#include<bits/stdc++.h>
using namespace std;
int n, k;
int a[10001]; 
bool b[10001];
void print()
{
	for(int i = 1; i <= n; i ++)
		cout << a[i] << " ";
	cout << endl;
}
void dfs(int x)
{
	for(int i = 1; i <= k; i ++)
	{
		if(!b[i])
		{
			a[x] = i;
			b[i] = 1;
			if(x == n)
				print();
			else
				dfs(x + 1);
			b[i] = 0;
		}
	}
}
int main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> n >> k;
	dfs(1);
	return 0;
}

不能输出重复的数字

2023/7/19 21:03
加载中...