题目:
现在有很多人在门口排队,每个人将会被发到一个有效的通行密码作为门票。一个有
效的密码由L(3 <= L <= 15)个小写字母(‘a’…’z’)组成,至少有一个元音(‘a’, ‘e’, ‘i’,
‘o’ 或 ‘u’)和两个辅音(除去元音以外的音节),并且是按字母表顺序出现的(例如,’abc’
是有效的,而’bac’不是) 。
mxy 想要知道今天的有效密码是什么。
现在给定一个期望长度L 和C(1 <= C <= 26)个小写字母,写一个程序,输出所有的
长度为L、能由这给定的C 个字母组成的有效密码。密码必须按字母表顺序打印出来,一行一个。
思路:
直接暴力就好了,注意要有元音之类的判断,还有就是按照字母序搜,直接出答案
const
maxn=5000;
var
s:array [1..maxn] of string;
c:char;
f:array ['a'..'z'] of boolean;
i,j,n,m,ans:longint;
function cheak(s:string):boolean;
var
i,j,x:longint;
begin
x:=0;
for i:=1 to length(s) do
if (s[i]='a') or (s[i]='e') or (s[i]='i') or (s[i]='o') or (s[i]='u')
then inc(x);
if (x>0) and (length(s)-x>1) then exit(true)
else exit(false);
end;
procedure dfs(dep:longint;c:char;s:string);
var
j:longint;
i:char;
begin
if (dep>n) then
begin
if (cheak(s)) then
begin
inc(ans);
writeln(s);
if ans=25000 then
begin
close(input); close(output);
halt;
end;
end;
exit;
end;
for i:=c to 'z' do
if f[i] then
begin
s:=s+i;
dfs(dep+1,chr(ord(i)+1),s);
delete(s,length(s),1);
end;
end;
begin
assign(input,'ticket.in'); reset(input);
assign(output,'ticket.out'); rewrite(output);
readln(n,m);
for i:=1 to m do
begin
read(c);
f[c]:=true;
read(c);
end;
dfs(1,'a','');
close(input); close(output);
end.