题目大意:
给出几个字母,字典序输出从小到大且有一个元音字母和两个辅音字母的字符串。
正文:
神怖题,爆搜。
代码:
void dfs(int x, int len, int Yuan, int Fu)
{
if(m - x + 1 + len < n || flag) return;
if(len == n && Yuan >= 1 && Fu >= 2)
{
printf("%s", ans + 1);
puts("");
total++;
flag = total >= 25000;
return ;
}
for (int i = x + 1; i <= m; i++)
{
ans[++tot] = a[i];
bool isY = (a[i] == 'a') || (a[i] == 'e') ||
(a[i] == 'i') || (a[i] == 'o') ||
(a[i] == 'u');
dfs(i, len + 1, Yuan + isY, Fu + (!isY));
ans[tot--] = ' ';
}
}
int main()
{
// freopen(".out", "w", stdout);
scanf ("%d%d", &n, &m);
for (int i = 1; i <= m; i++)
{
char c = getchar();
while (c < 'a' || c > 'z') c = getchar();
a[i] = c;
}
sort (a + 1, a + 1 + m);
dfs(0, 0, 0, 0);
return 0;
}