#6407. 【Python】ABCD排列组合 哪错了?

CPP 刷题王 2023-06-10 21:40:46 2023-06-10 21:40:52 0
#include <bits/stdc++.h>
using namespace std;
char c[5] = {' ', 'A', 'B', 'C', 'D'};
char a[5];
bool d[5];
int ans = 0;
void dfs(int step) {
	if (step == 4) {
		for (int i = 1; i <= 3; i++)
			cout << a[i];
		ans ++;
		puts("");
		return;
	}
	for (int i = 1; i <= 4; i++) {
		if (!d[int(c[i] - 'a')]) {
			a[step] = c[i];
			d[int(c[i] - 'a')] = true;
			dfs(step + 1);
			d[int(c[i] - 'a')] = false;
		}
	}
}
int main() {
	dfs(1);
	cout << ans;
	return 0;
}
{{ vote && vote.total.up }}

共 1 条回复

CPP 刷题王

?