-
Notifications
You must be signed in to change notification settings - Fork 0
/
DIN_BIBL.PAS
67 lines (56 loc) · 1.51 KB
/
DIN_BIBL.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
56
57
58
59
60
61
62
63
64
65
66
67
{ MK 2002 }
program bibliotekininkas;
const
maxlent = 9;
maxzm = 3;
type
Tlent = array [1 .. maxlent] of integer;
TV = array [1 .. maxzm, 1 .. maxlent] of integer;
var
lent : Tlent;
s, ck, ckzm, cklent, kiek, zm : integer;
suma : array [0 .. maxlent] of integer;
v : Tv;
Procedure nuskaitymas (var lent : Tlent; Var kiek, zm : integer);
var
f : Text;
ck : Integer;
begin
assign (f, 'lentyn.dat');
reset (f);
readln (f, kiek, zm);
for ck := 1 to kiek do
read (f, lent [ck]);
close (f)
end;
Function Max (sk1, sk2 : integer) : integer;
begin
if sk1 > sk2 then max := sk1
else max := sk2
end;
begin
nuskaitymas (lent, kiek, zm);
{ sumos }
suma [0] := 0;
for ck := 1 to kiek do
suma [ck] := suma [ck - 1] + lent [ck];
{ ribiniai atvejai }
for ck := 1 to kiek do { jei yra tik vienas zmogus, }
v [1, ck] := suma [ck]; { tai jis dalins iki ten, kur yra dedamas }
for ck := 1 to zm do { jei viena knyga ir daug zmoniu, tai... }
v [ck, 1] := lent [1];
{ dinaminis skaiciavimas is apacios }
for cklent := 2 to kiek do
for ckzm := 2 to zm do
begin
v [ckzm, cklent] := maxint;
for ck := 1 to cklent - 1 do
begin
s := max (v [ckzm - 1, ck], suma [cklent] - suma [ck]);
{ jei radome mazesnes sanaudas, tai jas issaugome }
if s < v [ckzm, cklent] then v [ckzm, cklent] := s
end
end;
{ atsakymas }
writeln ('Maksimalios sanaudos ', V [zm, kiek])
end.