-
Notifications
You must be signed in to change notification settings - Fork 0
/
DIN_SEK.PAS
55 lines (48 loc) · 1.04 KB
/
DIN_SEK.PAS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
{ MK 2002 }
program seka;
type
Tseka = array [1 .. 100] of integer;
var
f : text;
s, ilg, pries : Tseka;
ck1, ck2, pg, max : integer;
begin
{ prad duom skaitymas }
assign (f, 'seka.dat');
reset (F);
readln (f, pg);
for ck1 := 1 to pg do
read (f, s [ck1]);
close (f);
{ paleisim dinaminio programavimo principu paremta skaiciavima }
ilg [1] := 1;
pries [1] := 0;
for ck1 := 2 to pg do
begin
max := -maxint;
for ck2 := 1 to ck1 - 1 do
if (ilg [ck2] > max) and (s [ck1] > s [ck2]) then
begin
max := ilg [ck2] + 1;
pries [ck1] := ck2
end;
if max = -maxint then
begin
ilg [ck1] := 1;
pries [ck1] := 0;
end
else ilg [ck1] := max
end;
{ rasim ilgiausios sekos paskutini elementa }
max := - maxint;
for ck1 := 1 to pg do
if ilg [ck1] > max then max := ck1;
{ rasysim atsakymus }
pg := max;
for ck1 := 1 to ilg [max] - 1 do
begin
write (s [pg], ' ');
pg := pries [pg]
end;
writeln (s [pg])
end.