https://www.acmicpc.net/problem/1759
✔ 구현
0. l,c <=15 라서 모든 경우의 수를 구할 때 최대 연산이 15C7=6435 쯤 나오지 않을까
1. 주어진 L개의 문자를 오름차순으로 정렬한다.
2. 백트래킹으로 모든 케이스 비교하기
using namespace std;
#include <iostream>
#include <vector>
#include <algorithm>
int l, c;
int visit[15], ans[15];
char v[15];
bool vowels[15];
int main() {
cin >> l >> c;
for (int i = 0; i < c; i++)
cin >> v[i];
sort(v, v + c);
for (int i = 0; i < c; i++) {
if (v[i] == 'a' || v[i] == 'e' || v[i] == 'o' || v[i] == 'u' || v[i] == 'i')
vowels[i] = true;
}
combination(0, 0);
}
void combination(int cnt, int idx) {
if (cnt == l) {
int cnt = 0;
for (int i = 0; i < l; i++)
if (vowels[ans[i]]==true) cnt++;
//하나의 모음도 없거나 자음이 두개가 안 될 경우
if (cnt<=0 || (l-cnt)<2) return;
for (int i = 0; i < l; i++)
cout << v[ans[i]];
cout << '\n';
return;
}
for (int i = idx; i < c; i++) {
if (visit[i] == false) {
visit[i] = true;
ans[cnt] = i;
combination(cnt + 1, i + 1);
visit[i] = false;
}
}
}