【SSL 1374】 谷仓的安保

题目大意:

给出几个字母,字典序输出从小到大且有一个元音字母和两个辅音字母的字符串。

正文:

神怖题,爆搜。

代码:

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--] = '\0';
	}
}

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;
}
posted @ 2020-08-20 20:19  Jayun  阅读(284)  评论(0编辑  收藏  举报