6.006 21. Dynamic Programming III : Text justification, Knapsack
MIT OpenCourseWare http://ocw.mit.edu6.006Introduction to AlgorithmsSpring 2008For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. ������� �� ������� ����������� ��� �� �� ����� ������ ����������� ��� ������� ����������� ���� ���� ������������� ����������������� ��������� ���������������� ����� ������ �������� ������� �������� ���� ������������ • ���������������� • �������� • ���������������� ���� • ������ �������� • �������� ���� �� ������� � �� �� ��� ����� ����������� � �������� � � ���� ������ ��� ����� ������������ ����� � ������������ ����� ����� �� ���������� ����� � ���������� ������ �������� ���������� ������� ���������������� ������� � ������� �� ����� �� ����� ������ ������� � ������������� ×� �������� ������ ����������� ������� ������������ ��� ����� �������� ������� � � ���������� �� �������� ���� �� ����� � = ����� ����� ⇒ � ��� ���������� ���� ����������� ��� ����� ������� �� ������ �� ���������� �� � ������� �� ������� ����������� ��� �� �� ����� ������ �������� ������������� ����� ���� ���� ����� ������ ������� ��� ��������� ����� ���������� ��� �� ���� ����� �� �� ���� ����� ������ • ��� ���� ��� ���� ���� ��� �����• blahblahblahblahblahb l a hreallylongwordreallylongwordblahblahvs.....������ �� ���� ��� ��� ������������ • ����� �������(i, j) ��� ���� �� ����� [i : j] ����� �� ����� ������ > ���� ����� (���� ����� � ����� ������)3 ���� ����� ����� ����� ���� ����� �� min �������• �� ���������� � min ������� ��� ���� �����[i :] = � ����������� = Θ(n) ����� n = � ����� ⇒ �� �������� � ����� �� ��� ���� ����� ��� i : j = ⇒ � ������� = n − i = O(n) �� ��������� • ��[i] = min��������(i, j) � ��[j] ��� j �� �����(i +1,n + 1)� • ��[n]= φ= ���� ��� ���������� = O(n)⇒ �� ����� ���� = O(n2) �� �������� = ��[φ] �� ��� ������ �������� �� ������� ������ �������� �� ������� ����������� ��� �� �� ����� ������ ��������������������� ������� ���������� �� ����������� ���������� � ����� ����������� ����������� �������� ..ABC(AB)C costs (n2)A(BC) costs (n)������ �� Evaluation of an Expression �� �������� � ��������� �������������� (��)(��)······↑k−1 ↑k = � ������� = O(n)⇒ �� ����������� � ������� � �������� ��� ���� �� ��������� A[i : j]= � ����������� � Θ(n2)⇒ �� ��������� • ��[i, j] = min(�� [i, k]+ ��[k, j]+ ���� �� ����������� (A[i] ··· A[k − 1]) �� (A[k] A[j − 1]) ��� k �� �����(i +1,j))··· • ��[i, i +1] = φ= ���� ��� ���������� = O(n)⇒ �� ����� ���� = O(n3)�� �������� = DP [0,n]�� ��� ������ �������� �� ������� �������� ��������� �������� �� ���� S ��� ���� �� ���� • ���� i ��� ������� ���� si � ���� ����� vi • ����� ������ ������ �� ����� �� ������� ����� ����� ������� �� ����� ���� ≤ S ����� �������� �� ���������� � ����� ��� ����� �� ������� �������� � ������� �� ������� ���� i = � ������� � 2⇒ �� ��������� � ������� �� ������� ����������� ��� �� �� ����� ������ ����• si ≤ S?!)DP [i] = max(DP [i + 1],vi + DP [i + 1] ����� ��� ������ ����������� �� ���� ������� ���� i ��� � ��� ���� ����� �� �����• ������ �� ���������� � ����� ��� ���� i������ �������� �� ���� X= � ����������� = O(nS) �⇒ �� ��������� • DP [i, X] = max(DP [i +1,X],vi + DP [i +1,X − si] �� si ≤ X) • DP [n, X]= φ= ���� ��� ���������� = O(1)⇒ �� ����� ���� = O(nS) �� �������� = DP [φ, S] �� ��� ������ �������� �� ������� ������� �������� ���������� ������ ��� �������� �������� �������� �� �� ���� ������������ = ������� �� ��������������� ��������� �����������⇒ �� ������ �� ������� ���� ������ • ���� ����� =< S,s0, ··· ,sn−1,v0, ··· ,vn−1 > • ������ �� ������� O(lg S + lg s0 + ··· ) ≈ O(n lg ...) • �� O(nS) �� ��� ����������������� • O(nS) ����� ������ ���� �� S �� ����� ����������������� ������ ���������� �� ������ �� ����� � �������� �� ��� �����• ��������� ���������� � ���� ����������� � ��� ���������� � �� �� �������� �� ������� ����������� ��� �� �� ����� ������ ���������� �� ������ ������ ��������� ����� �������� �� n ������ ������ � � ����� �� ����� ����� w• ���� ������ ����������� � x ���������� ��� ���� • ���� ���� ���� ����� ���� �� ���� ��������� • ���� ���� �� ��� ����� • ������� ����� �������������� �� ����� ����� ����� �� w ����� ���� ������������ ����� ������� ����� ���� ������ ������ h• ��������� ����� ������� �� ����������� ����� �������� �� ���������� � ������� �� ����� i�� ����� �� �������� � ��� �� ���� ����� i = � ������� = O(w)⇒ �� ��������� DP [i]= DP [i + 1] �� ��� ������ ������������ ���� �� �� ���� �� ���� ����� ����� � �� �� ���������� � �������� �� ���� i������ ������� ������ ����������� h0,h1, ,hw−1··· = � ����������� = O(nhw)⇒· �� ��������� DP [i, h] = max(DP [i, m] ��� ����� ����� m �� ����� i �� h)= ���� ��� ���������� = O(w)⇒ �� ����� ���� = O(nwhw) �� �������� = DP [φ, φ] �� ��� ������ �������� �� ������� ������ �
Description
In this lecture notes we are going to continue with Dynamic Programming . The topics covered in this section are 1.Text Justification
2. Parenthesization, 3.Knapsack, 4.Pseudopolynomial Time and 5. Tetris Training. Dynamic programming is all about subproblems & guessing.
Instructors: Prof. Erik Demaine, Prof. Ronald Rivest, Prof. Srinivas Devadas, MIT Course Number: 6.006 Level: Undergraduate, 6.006 21. Dynamic programming III: text justification, parenthesization, knapsack, pseudopolynomial time, Tetris training ,Introduction to Algorithms, Electrical Engineering and Computer Science, Engineering, Massachusetts Institute of Technology: MIT Open Course Ware, http://ocw.mit.edu (02-11-2011). License: Creative Commons BY-NC-SA: http://ocw.mit.edu/terms/#cc.
Presentation Transcript
Your Facebook Friends on WizIQ