Xinh hay nhất.
Bài này tương tự bài quy hoạch động tăng dần có liên tiếp, nhưng không dùng mảng t.
uses crt;
var d,f:text; i,n,j,x:longint; l:array[0..100000]of longint;
s:string;
a:array[0..100000]of char;
begin
clrscr;
assign(d,'input.pas');reset(d);
assign(f,'output.pas');rewrite(f);
readln(d,s);
for i:=1 to length(S) do if s[i]=upcase(s[i]) then begin inc(n); a[n]:=s[i]; end;
a[0]:='=';
for i:=n downto 0 do
begin
l[i]:=1;
for j:=i+1 to n do
if (a[i]<a[j])and(l[j]+1>l[i]) then l[i]:=l[j]+1;
end;
writeln(f,l[0]-1);
close(f);
close(d);
end.
Bảng phương án: