Deskripsi untuk soal nomor 31 - 33
Perhatikan program berikut:
var
i,j:integer;
A: array[0..9,0..10] of integer;
qr,qc: array[0..10000] of integer;
mr: array[0..3] of integer = (0,1,0,-1);
mc: array[0..3] of integer = (1,0,-1,0);
area: array[0..9,0..10] of char =
( ('o','l','i','m','p','i','a','d','e','s','a'),
('i','n','s','t','i','n','g','k','a','t','p'),
('r','o','v','i','n','s','i','2','0','1','1'),
('.','i','o','i','2','0','1','1','d','i','a'),
('d','a','k','a','n','d','i','t','h','a','i'),
('l','a','n','d','.','g','o','g','e','t','g'),
('o','l','d','s','i','n','d','o','n','e','s'),
('i','a','.','b','e','p','r','e','p','a','r'),
('e','d','f','o','r','i','o','i','2','0','1'),
('1','.','i','n','d','o','n','e','s','i','a')
);
procedure init;
var
i:integer;
j:integer;
begin
for i:=0 to 9 do for j:=0 to 10 do A[i,j]:= 9999;
end;
procedure S_B;
var
i,h,t: integer;
begin
init;
h:=0; t:=0;
qr[t] := 2; qc[t] := 1;
A[qr[t],qc[t]] := 0;
t:=t+1;
while (h<t) do
begin
for i:=0 to 3 do
if ((0<=qr[h]+mr[i]) and (qr[h]+mr[i]<=9) and
(0<=qc[h]+mc[i]) and (qc[h]+mc[i]<=10)) and
{soal 33} (area[qr[h]+mr[i],qc[h]+mc[i]] <> 'i') and
{soal 33} (A[qr[h]+mr[i],qc[h]+mc[i]] > A[qr[h],qc[h]]) then
begin
qr[t] := qr[h]+mr[i];
qc[t] := qc[h]+mc[i];
A[qr[t],qc[t]] := A[qr[h],qc[h]]+1;
t:=t+1;
end;
h:=h+1;
end;
end;
Setelah procedure S_B
dipanggil, berapakah nilai A[0][10]
?
Berapakah nilai maksimum di antara semua nilai yang tersimpan pada matriks A?
Jika baris 43 dan 44 diganti dengan
(area[qr[h]+mr[i],qc[h]+mc[i]] <> 'i') then
, berapakah nilai A[9][0]
saat procedure S_B
dipanggil?