재귀, 백트래킹, 조합, 을 통해 풀이했다.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int L, C;
int vowel = 0;
int consonant = 0;
vector<char> s;
char ans[15];
void recur(int depth, int next)
{
if (depth == L)
{
vowel = 0;
consonant = 0;
for (int i = 0; i < L; i++)
{
if (ans[i] == 'a' ||
ans[i] == 'e' ||
ans[i] == 'i' ||
ans[i] == 'o' ||
ans[i] == 'u')
{
vowel++;
}
else
{
consonant++;
}
}
if (vowel < 1 || consonant < 2)
{
return;
}
for (int i = 0; i < L; i++)
{
cout << ans[i];
}
cout << '\n';
return;
}
for (int i = next; i < C; i++)
{
ans[depth] = s[i];
recur(depth + 1, i + 1);
}
}
int main()
{
cin >> L >> C;
char input;
for (int i = 0; i < C; i++)
{
cin >> input;
s.push_back(input);
}
sort(s.begin(), s.end());
recur(0,0);
return 0;
}
'프로그래밍 공부 > 백준 (C++)' 카테고리의 다른 글
[C++ / 백준 2529번] 부등호 (0) | 2025.01.13 |
---|---|
[C++ / 백준 14889번] (재귀 / 비트마스크) 스타트와 링크 (0) | 2025.01.07 |
[C++ / 백준 10972번] 다음 순열 (0) | 2024.12.29 |
[ C++ / 백준 15663번 ] N과 M (9) (0) | 2024.12.28 |
[백준 15649번, 15650번 / C++] N과 M (0) | 2024.12.19 |