Grokking Algorithms



Download 6,4 Mb.
Pdf ko'rish
bet82/120
Sana21.12.2022
Hajmi6,4 Mb.
#893167
1   ...   78   79   80   81   82   83   84   85   ...   120
Bog'liq
Grokking Algorithms An Illustrated Guide for Programmers and Other

Chapter 9
 
 
I
 
 
Dynamic programming
At this point, your grid should look like this.
Remember, you’re trying to maximize the value of the knapsack. 
his row represents the current best guess for this max.
So right now, 
according to this row, if you had a knapsack of capacity 4 lb, the max 
value you could put in there would be $1,500.
You know that’s not th
e inal solution. As we go through the algorithm
you’ll reine your estimate. 
The stereo row
Let’s do the next row. his one is for the stereo. Now that you’re on the 
second row, you can steal the stereo or the guitar. At every row, you can 
steal the item at that row or the items in the rows above it. So you can’t 
choose to steal the laptop right now, but you can steal the stereo and/or 
the guitar. Let’s start with the irst cell, a knapsack of capacity 1 lb. he 
current max value you can it into a knapsack of 1 lb is $1,500.


167
The knapsack problem
Should you steal the stereo or not? 
You have a knapsack of capacity 1 lb. Will the stere
o it in there? Nope, 
it’s too heavy! Because you can’t it the stereo, $1,500
remains
the max
guess for a 1 lb knapsack.
Same thing for the next two cells. hese knapsacks have a capacity of
2 lb and 3 lb. he old max value for both was $1,500.
he stereo still doesn’t it, so your guesses remain unchanged.
What if you have a knapsack of capacity 4 lb? Aha: the stereo inally its! 
he old max value was $1,500, but if you put the stereo in there instead
the value is $3,000! Let’s take the stereo.


168
Chapter 9
 
 

Download 6,4 Mb.

Do'stlaringiz bilan baham:
1   ...   78   79   80   81   82   83   84   85   ...   120




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish