# 20. Dynamic Programming II: Text Justification, Blackjack

MIT 6.006 Introduction to Algorithms, Fall 2011
View the complete course: http://ocw.mit.edu/6-006F11
Instructor: Erik Demaine

More courses at http://ocw.mit.edu

1. Benyamin Beyzaie on September 12, 2021 at 10:15 pm

Did any one has taken notes from these lectures?

2. mohit rao on September 12, 2021 at 10:16 pm

Can somebody explain, Why was 1 added to indegree(v)?
At one point he says it’s for memorization(12:55) and then at another point he says it’s account for 0 edges(10:25).

Great lecture! Thanks Erik and MIT.

3. Laurie Tsao on September 12, 2021 at 10:19 pm

OMG, basic strategy is to hit soft 18 vs 9 or T. Victor erred on both hands. Casing the entire deck makes much more for baccarat, not blackjack. And in reality you’d double, split, and change the number of hands. It gets more interesting if you have partial omniscient information, say suborderings of cards.

4. Janac Meena on September 12, 2021 at 10:21 pm

35:16 – Parent Pointers

5. IWillTakeAGuranteeOfBetterOverAPromiseOfPerfect on September 12, 2021 at 10:23 pm

Professor: " This talk will be about DPs and BJ with some text justification."

Professor: "About BJ, (as I said at 49:15) if I’ve already busted, I can’t hit again"
Interviewer: "But what is the general starting point?"
Professor: "Well the base case for a 2×3^2 problem is 18 but as I said at 49:18 : maybe I take another hit , maybe I take another hit again, maybe I take another hit again. At some point I go over 21 and then you have got to stop the for loop."
Interviewer: "What exactly are we talking about? Weed? Young women?"
Professor: "Absolutely not. THIS IS COMPUTER SCIENCE! (/SPARTA) =D"

6. Shubham Singh on September 12, 2021 at 10:25 pm

Ah, Counting cards.

7. Adarsh Gupta on September 12, 2021 at 10:26 pm

Why word’s strategy is not better

8. fgfanta on September 12, 2021 at 10:27 pm

I have a hard time finding how "page width" is actually computed in badness(i, j).

9. Sergey Kholkhunov on September 12, 2021 at 10:34 pm

00:00 review of last lecture
05:53 five "easy" steps to DP
08:40 step 1: define sub-problems
09:51 step 2: guess (part of solution)
11:06 step 3: relate sub-problems
13:15 step 4: recurse and memoize or build DP table bottom-up
15:28 step 5: solve original problem
17:05 text justification
35:12 parent pointers
38:50 blackjack

10. Ben C on September 12, 2021 at 10:35 pm

5 easy steps to DP: 2 in the pink, 1 in the stink.

11. ramnath teja chekka on September 12, 2021 at 10:36 pm

Okay, now my question is what to do with the infinite loop on Erik’s T-shirt!!

12. Research and Build on September 12, 2021 at 10:36 pm

I dont get it…sorry..

13. Hadoren on September 12, 2021 at 10:38 pm

Yeah unfortunately this was really confusing. No code examples, no clarity, just random babble that left me utterly confused.

14. moein kasraei on September 12, 2021 at 10:38 pm

اهل مدرسه را به اهالی مدرسه پاس می دهند ،مگر خودشان اینرا نمی خواهند
واهل تحقیق همدیگر را می شناسند

15. Pablo Garin on September 12, 2021 at 10:39 pm

hearing "DP" and "BJ" in a video made me wonder if I was watching the wrong kind of video :V

16. Adhish Malviya on September 12, 2021 at 10:40 pm

Bolo siyavar ram chandra ki jai!

17. Lizard King on September 12, 2021 at 10:43 pm

dynamic programming in 5 easy steps that silicon valley don’t want you to know!

18. Sia Ahmadi on September 12, 2021 at 10:43 pm

I wonder how you’d handle the value of Ace in the blackjack algorithm

19. c sl on September 12, 2021 at 10:44 pm

20:48 "why cubed? who knows". I wonder if this is to penalize big badness in an exaggerated way compared to small badness (so that, say, a badness of 2 is not twice as bad, but 8 times as bad as a badness of one). It seems to me that the effect of this is to favour justifications with a large number of lines that are just a little bit bad, over justifications with a few very bad lines. It sort of reminds me of the different error/objective functions in machine learning, if you know what I mean. The exponent (the 3) could be regarded as a (meta?) parameter of sorts, and it might even make sense to apply machine learning to text justification, where the optimal value for this exponent is learned from a large number of texts that were manually justified.

20. Aditya K Surikuchi on September 12, 2021 at 10:44 pm

Actually the "shortest paths in some DAG" perspective for dynamic programming could be a very slippery slope

21. Shrreya Behll on September 12, 2021 at 10:46 pm

at 49:00 , why is the range from(i+4,n)? what does 4 in i+4 signify?

22. HARDIK CHAWLA on September 12, 2021 at 10:47 pm

Great explanation

23. Balaporte Jean on September 12, 2021 at 10:48 pm

wohhh great
Jesus loves you
Believe in him and repent !

24. tririverwangyi on September 12, 2021 at 10:49 pm

The "latest" Word as of 2013 does not have smart line justification. Now it’s 2019 Word still does not have it. From time to time I have to delete/change a word to make the next line not too ugly…

25. Vamsi K on September 12, 2021 at 10:50 pm

But how do we add memoization to the recursive text justification algorithm?

26. Pearz on September 12, 2021 at 10:51 pm

For an academic video, there are a lot of n-words.

27. IncinerateZ on September 12, 2021 at 10:52 pm

An algorithmic problem I was trying to solve required Dynamic Programming (Kickstart 2020 Plates) as the optimal solution. Scratched my head so much looking at the solution and time complexity thinking : "isnt this just brute force?".

28. Apple Puddings on September 12, 2021 at 10:54 pm

Such lectures are never free people pls young people if u are plannig to go for any university then also u have to pay like I am paying

29. Aristos Georgiou on September 12, 2021 at 10:55 pm

26:22 … No this is what makes dynamic programming .. well, dynamic programming!

30. c sl on September 12, 2021 at 10:55 pm

The "5 Steps" are pedagogical gold

31. Dennis Jordan on September 12, 2021 at 10:56 pm

16:46 — Text justification
38:50 — Blackjack

32. Julius Newman on September 12, 2021 at 10:58 pm

Do MIT students ever ask questions?

33. LT1FirebirdSLP on September 12, 2021 at 10:58 pm

Parent Pointers begins at 35:17

34. Ilias P on September 12, 2021 at 11:00 pm

can’t belive he said "the n-word" so many times and got away with it

35. Research and Build on September 12, 2021 at 11:01 pm

Cubed..i wonder if its rule of thirds?

36. Fouchimi Ousmane on September 12, 2021 at 11:02 pm

This doesn’t really help much. How would you define badness?

37. Isaac Weaver on September 12, 2021 at 11:02 pm

At 33:23 shouldn’t the run time actually be O(n(n+1)/2) instead of O(n^2)? If you think about it as starting with i = n – 1 and working backward to i=0, then the for loop iterations in the min statement will look like this:

range(n, n+1) – 1 iteration
range(n – 1, n+1) – 2 iterations
range(n – 2, n+1) – 3 iterations

range(0, n+1) – n iterations

The runtime should just be the sum of integers 1 to n, which by induction is n(n+1)/2 which is significantly faster then n^2

38. Sơn Dương Vân on September 12, 2021 at 11:03 pm

49:48 to 50:12
Can someone explains me why j equal to i + 4 + #hits +#dealer-hits? Thank you

39. Maninandadeep medicharla on September 12, 2021 at 11:03 pm

this guy is brilliant !!

40. frankhv on September 12, 2021 at 11:04 pm

Those 5 guys who until this moment gave their dislikes I believe they are taking courses at high school. Btw, this professor is amazing! He motivated me much more that I usually used to be doing.

41. Robert Alaverdyan on September 12, 2021 at 11:05 pm

Excellent. for me watching these lectures is like watching moves : relaxing but very useful and entertaining

42. Lp Xiv on September 12, 2021 at 11:06 pm

for the text justification, i cant see where the memoization happens. To me, DP(i) is a recurrence function that elaborates the subproblems and min(dp for j in range(…)] is just gonna calculate all the possible new lines. I guess we are to maintain a memo table in the course of bottom up actions which are automated at the end of recurrence? is the job of the memo table to record the dp of i onwards that might have repeated in the course of elaboration？

43. Ian Hart on September 12, 2021 at 11:07 pm

Good old chalk talk

44. Mike Wakefield Geller on September 12, 2021 at 11:08 pm

11 minutes in ..any questions? No.

45. Janac Meena on September 12, 2021 at 11:10 pm

38:52: Blackjack

46. Cla 200 on September 12, 2021 at 11:11 pm

how is this different from original word greedy approach? this is the greedy approach. just take as much as you can on one line and recurse

47. Giovani Ventrue on September 12, 2021 at 11:12 pm

Why cubed? Who knows.

48. Pablo Garin on September 12, 2021 at 11:12 pm

It makes sense to cube the result to obtain the badness: you preserve the sign, so you can know if your line is too large or too small…

49. Chaleelaleela on September 12, 2021 at 11:12 pm

I don’t understand the text justification problem. Someone pls helps me.

50. EE Passion on September 12, 2021 at 11:13 pm

40:28 that Hoodie Shirt meaning MIT 🙂 for who curious