Grokking Algorithms



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

Knapsack problem FAQ
Maybe this still feels like mag
ic. his section answers some common 
questions. 
What happens if you add an item?
Suppose you realize there’s a fourth item you can steal that you didn’t 
notice before! You can also steal an iPhone.
Do you have to recalculate everything to account for this new item? 
Nope. Remember, dynamic programming keeps progressively 
building on your estimate. So far, these are the max values.
hat means for a 4 lb knapsack, you can steal $3,500 worth of goods. 
You thought that was the inal max value. But let’s add a row for
the iPhone.


172
Chapter 9
 
 
I
 
 
Dynamic programming
Turns out you have a new max value! Try t
o ill in this new row before 
reading on. 
Let’s start with the irst cell. he iPhone its into the 1 lb knapsack. 
he old max was $1,500, but the iPhone is worth $2,000. Let’s take the 
iPhone instead.
In the next cell, you can it the iPhone 
and
the guitar.
For cell 3, you can’t do better than take the iPhone and the guitar again
so leave it as is.
For the last cell, things get interesting. he current max is $3,500. You 
can steal the iPhone instead, and you have 3 lb of space let over.


173
Knapsack problem FAQ
hose 3 lb are worth $2,000! $2,000 from the iPhone + $2,000 from the 
old subproblem: that’s $4,000. A new max!
Here’s the new inal grid.
Question: Would the value of a column ever go 
down
? Is this possible?
hink of an answer before reading on. 
Answer: No. At every iteration, you’re storing the current max estimate. 
he estimate can never get worse than it was before!

Download 6,4 Mb.

Do'stlaringiz bilan baham:
1   ...   80   81   82   83   84   85   86   87   ...   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