Perhatikan potongan program berikut ini:
function tahu(x,y:longint):longint;
begin
if (x<1) or (y<1) then tahu := 0
else if (x=1) or (y=1) then tahu :=1
else tahu := tahu(x-2, y-1) + 2*tahu(x-1,y-2) + 1;
end;
Berapakah hasil dari pemanggilan tahu(4,5)?
Siswa SMA Negeri 68 Jakarta
t(4,5) = t(2,4) + 2*t(3,3) + 1
t(2,4) = t(0,3) + 2*t(2,1) + 1 //t(0,3) = 0, t(2,1) = 1
t(3,3) = t(1,2) + 2*t(2,1) + 1 //t(1,2) = 1, t(2,1) = 1
maka hasilnya adalah 12
t(4,5) = t(2,4) + 2*t(3,3) + 1
t(2,4) = t(0,3) + 2*t(2,1) + 1 = 0 + 2*1 + 1 = 3
t(3,3) = t(1,2) + 2*t(2,1) + 1 = 1 + 2*1 + 1 = 4
t(4,5) = 3 + 2*4 + 1 = 12
Masuk untuk menulis jawaban