20分求助!!!
查看原帖
20分求助!!!
730195
Little_Cabbage楼主2023/4/27 16:20

提交记录

#include <bits/stdc++.h>
#include <iomanip>
#define ll long long
using namespace std;
const ll N = 20;
ll n, a[N], x;
bool f[N];

void dfs(ll d, ll k) {
	if (d == n) {
		a[d] = k;
		for (int i = 1; i <= n; i++)
			cout << setw(3) << a[i] << ' ';
		cout << endl;
	} else {
		a[d] = k;
		f[k] = true;
		for (int i = 1; i <= x; i++)
			if (f[i] == false && i > k)
				dfs(d + 1, i);
		f[k] = false;
		a[d] = 0;
	}
}

int main() {
	cin >> x >> n;
	for (int i = 1; i <= x; i++)
		dfs(1, i);
	return 0;
}
2023/4/27 16:20
加载中...