正题
题目大意
给定一些字母,用字母组成一个单词要求满足
- 从小到大
- 有1个元音字母
- 有2个辅音字母
- 长度为LLL
输出字典序最小的250002500025000个。
解题思路
暴力搜索时间复杂度
O(CNL)O(C_{N}^L)O(CNL)
codecodecode
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int l,c,z,C;
char k[100],a[100];
void dfs(int dep,int A,int B,int c)
{if(!z) return;if(!c){if(A>0||B>0) return;for(int i=l;i>0;i--)putchar(k[i]);putchar('\n');z--;return;}if(C-dep+1<c) return;bool mark=0;if(a[dep]=='a'||a[dep]=='e'||a[dep]=='i'||a[dep]=='o'||a[dep]=='u')mark=1;k[c]=a[dep];dfs(dep+1,A-mark,B-(mark^1),c-1);dfs(dep+1,A,B,c);
}
int main()
{freopen("data.out","w",stdout);z=25000;scanf("%d%d",&l,&c);C=c;for(int i=1;i<=c;i++)cin>>a[i];sort(a+1,a+1+c);dfs(1,1,2,l);
}