Dynamic Programming_Upto MidSem.pdf
Document Details
Uploaded by EarnestVoice
Full Transcript
Lecture/Practice Questions Dynamic Programming Q1: https://leetcode.com/problems/longest-common-subsequence/description/ Solution (Memoization): class Solution { public: int longestCommonSubsequence(string text1, string text2) { int m=text1.length();...
Lecture/Practice Questions Dynamic Programming Q1: https://leetcode.com/problems/longest-common-subsequence/description/ Solution (Memoization): class Solution { public: int longestCommonSubsequence(string text1, string text2) { int m=text1.length(); int n=text2.length(); vector l(m+1,vector(n+1,-1)); return LCS(text1,text2,m,n,l); } int LCS(string &text1,string &text2,int m,int n,vector &l) { if(l[m][n]==-1) { //cout