Académique Documents
Professionnel Documents
Culture Documents
1. penempatan 4 ratu
Gambarkan pohon pelacakan untuk penempatan 4 ratu pada papan 4x4 seperti
gambar dibawah ini. Aturan bahwa tidak boleh ada dua ratu atau lebih berada dalam 1
baris, satu kolom atau diagonal berdekatan. Gunakan algoritma backtracking, untuk
mengulangi simulasi.
Q
1
f.
i.
2.
bcost(2,1) = c(0,1) = 5
bcost(2,2) = c(0,2) = 3
bcost(3,3) = c(1,3) + bcost(2,1)
bcost(3,3) = 1 + 5 = 6
bcost(3,4) = min { c(1,4) + bcost(2,1) | c(2,4) + bcost(2,2) }
bcost(3,4) = min { 3 + 5 | 8 + 3 } = 8
bcost(3,5) = min { c(1,5) + bcost(2,1) | c(2,5) + bcost(2,2) }
bcost(3,5) = min { 6 + 5 | 7 + 3 } = 10
bcost(3,6) = c(2,6) + bcost(2,2)
bcost(3,6) = 6 + 3 = 9
bcost(4,7) = min { c(3,7) + bcost(3,3) | c(4,7) + bcost(3,4) }
bcost(4,7) = min { 6 + 6 | 3 + 8 } = 11
bcost(4,8) = min { c(3,8) + bcost(3,3) | c(4,8) + bcost(3,4) | c(5,8) + bcost(3,5) | c(6,8) +
bcost(3,6) }
bcost(4,8) = min { 8 + 6 | 5 + 8 | 3 + 10 | 8 + 9 } = 13
bcost(4,9) = min { c(5,9) + bcost(3,5) | c(6,9) + bcost(3,6) }
bcost(4,9) = min { 3 + 10 | 4 + 9 } = 13
bcost(5,10) = c(7,10) + bcost(4,7)
bcost(5,10) = 2 + 11 = 13
bcost(5,11) = min { c(7,11) + bcost(4,7) | c(8,11) + bcost(4,8) | c(9,11) + bcost(4,9)}
bcost(5,11) = min { 2 + 11 | 1 + 13 | 3 + 13 } = 13
bcost(5,12) = min { c(8,12) + bcost(4,8) | c(9,12) + bcost(4,9) }
bcost(5,12) = min { 2 + 13 | 3 + 13 } = 15
bcost(6,13) = min { c(10,13) + bcost(5,10) | c(11,13) + bcost(5,11) | c(12,13) + bcost(5,12) }
bcost(6,13) = min { 3 + 13 | 5 + 13 | 6 + 15 } = 16
bcost(6,14) = min { c(10,14) + bcost(5,10) | c(11,14) + bcost(5,11) | c(12,14) + bcost(5,12) }
bcost(6,14) = min { 5 + 13 | 2 + 13 | 6 + 15 } = 15
bcost(7,15) = min { c(13,15) + bcost(6,13) | c(14,15) + bcost(6,14) }
bcost(7,15) = min { 4 + 16 | 3 + 15 } = 18
Jadi lintasan terpendek adalah 0-1-4-7-11-14-15 dengan cost = 18
3. A. y = (a +b) (c d)/bc
LOAD B
MPY C
STORE T1
LOAD C
SUB D
DIV T1
STORE T2
LOAD A
ADD B
SUB T2
STORE Y
B. x = ab (cd)/(2a-b)
LOAD A
ADD A
SUB B
STORE T1
LOAD C
MPY D
DIV T1
STORE T2
LOAD A
MPY B
SUB T2
STORE X