3. Tickets
"Problem description"
The MXY is going through the New World gate.
There are a lot of people standing in line at the door and everyone will be sent a valid passcode as a ticket. One has
The valid password is composed of L (3 <= L <= 15) lowercase letters (' a ' ... ' z '), with at least one vowel (' a ', ' e ', ' I ',
' O ' or ' u ') and two consonants (except for syllables other than vowels) and appear in alphabetical order (for example, ' abc ')
is effective, and ' BAC ' is not).
Mxy want to know what the valid password is today.
Now given an expected length of L and C (1 <= C <= 26) lowercase letters, write a program that outputs all
A valid password of length l, which can be made up of this given C letter. The password must be printed in alphabetical order, one line
One.
Input
Input data total 2 rows.
Line 1th: Two integers separated by a space, L and C. (3 <= L <= 15,1 <= C <= 26)
Line 2nd: C A lowercase letter separated by 1 spaces, the password is constructed by the letters in the letter set.
Output
Several lines, each of which outputs a password with a length of L characters (no spaces). The output line must be in alphabetical order
Arranged. Your program only needs to output the first 25,000 valid passwords, even if there is a valid password behind it.
Analysis : First the letter from small to large sort, and then directly DFS, judge the vowel consonants or something good.
Code
Var
L,c,i,j,sum:longint;
Ch:char;
A,B:ARRAY[0..26] of Char;
F:ARRAY[0..26] of Boolean;
function Check:boolean;
Var
I,p:longint;
Begin
p:=0;
For I:=1 to L do
If b[i] in [' A ', ' e ', ' I ', ' o ', ' U '] then Inc (P);
if (p>=1) and (l-p>=2) then exit (true);
Exit (FALSE);
End
Procedure Dfs (Dep,x:longint);
Var
I:longint;
Begin
if (dep>l) and (check) then
Begin
Inc (SUM);
If sum>25000 Then
Begin
Halt
Close (input); close (output);
End
For I:=1 to L do
Write (B[i]);
Writeln;
Exit
End
For i:=x+1 to C do
Begin
B[dep]:=a[i];
DFS (dep+1,i);
End
End
Begin
//assign (input, ' ticket.in '); reset (input);
//assign (output, ' ticket.out '); rewrite (output);
Readln (L,C);
Read (a[1]);
for i:=2 to C do
Read (Ch,a[i]);
for I:=1 to C-1 does
for j:=i+1 to C does
if A[I]>A[J] then
begin
A[0]:=a[i];
A[i]:=a[j];
A[j]:=a[0];
End;
Dfs (1,0);
Close (input); close (output);
End.