【洛谷P1061 Jam的计数法】搜索
分析
超级暴力,在尾部+1,再判断。
AC代码
type
arr=array[0..27]of longint;
var
st:string;
a:array[0..27]of longint;
s,t,w,i:longint;
procedure print(a:arr);
var
i:longint;
begin
for i:=w downto 1 do write(chr(a[i]+96)); writeln;
end;
function check(a:arr):boolean;
var
i:longint;
begin
for i:=w-1 downto 1 do
if (a[i+1]<=a[i])and(not((a[i]>=s)and(a[i]<=t)and(a[i+1]>=s)and(a[i+1]<=t))) then exit(false);
exit(true);
end;
procedure solve(a:arr);
var
i,cnt,kkk:longint;
begin
cnt:=0;
while cnt<5 do
begin
inc(a[1]); kkk:=1;
for i:=1 to w do
if a[i]>t then
begin
a[i]:=s;
inc(a[i+1]);
end;
for i:=w-1 downto 1 do
if a[i]<a[i+1] then a[i]:=a[i+1]+1;
//print(a);
if check(a) then
begin
inc(cnt); print(a);
end;
end;
end;
begin
readln(s,t,w);
readln(st);
for i:=w downto 1 do a[i]:=ord(st[w-i+1])-ord('a')+1;
solve(a);
end.
黎明的朝阳,会为苦难中最坚强的信念升起