1 answer

I need this using C++. In this project, you will implement the dynamic programming-based solution to...

Question:

I need this using C++.
In this project, you will implement the dynamic programming-based solution to find the longest common subsequence (LCS) of tw
In this project, you will implement the dynamic programming-based solution to find the longest common subsequence (LCS) of two sequences. Your inputs will be the two sequences (as Strings) and the outputs are the longest common subsequence (printed as a String) and the final matrix (printed as a two-dimensional array) depicting the length of the longest common subsequences (as shown in the slides) for all possible subsequences of the two input sequences. The two input sequences to be used by each student are shown below. The LCS expected for the two sequences is also shown. Row Sequence Column Sequence GGGGTAACT LCS TCT TCGCCTT Asample output is shown below Column Sequence: ATGCGGGG A word document containing the following: Row Sequence: ou Sequence: ATTAGTGGA Submission (through Canvas: (i) entire code (ii) the outputs showing the final dynamic programming table (of the lengths of the longest common subsequences of all possible subsequences of the two input strings) and the longest common subsequence 1 2 2 2 2 2 2 2 2 0 1 2 2 2 2 2 2 2 2 0 1 2 2 2 2 2 2 2 2 0 1 2 3 33 3 33 3 0 1 2 3 33 3 3 3 3 0 1 2 33 4 4 4 4 4 0 1 2 3 3 4 4 4 4 4 1 2 3 4 4 4 4 4 5 0 1 2 3 4 5 5555 0 1 2 3 4 55555 LCS: ATGGC

Answers

A example given in sample output with answer ATGGC is wrong

There can be many lcs for a pair of strings i have only printed one

#include <bits/stdc++.h>
using namespace std;
void LongestCommonSubsequence(string X,string Y)
{
   int m=X.length(),n=Y.length();
   int dp[m+1][n+1];
   //initialise dp with 0
   memset(dp,0,sizeof(dp));
   for(int i=0;i<=m;i++)
   {
       for(int j=0;j<=n;j++)
       {
           //if length of any of the string is 0 its lcs is 0
           if(i==0||j==0)
           dp[i][j]=0;
           //if two characters are equal
           else if(X[i-1]==Y[j-1])
           dp[i][j]=1+dp[i-1][j-1];
           else if(X[i-1]!=Y[j-1])
           dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
       }
   }
   //lcs stores answer
   string lcs="";
   // Start from the right-most-bottom-most corner and
// one by one store characters in lc
   int i=m,j=n;
   while(i>0 && j>0)
   {
       if(X[i-1]==Y[j-1])
       {
           lcs=lcs+X[i-1];
           i--;
           j--;
       }
       else if(dp[i-1][j]>=dp[i][j-1])
       i--;
       else if(dp[i-1][j]<dp[i][j-1])
       j--;
   }
   //print matrix
   for(int i=0;i<=m;i++)
   {
       for(int j=0;j<=n;j++)
       cout<<dp[i][j]<<" ";
       cout<<endl;
   }
   //lcs will be reverse of actual answer so reverse it and print it
   reverse(lcs.begin(),lcs.end());
   cout<<lcs<<endl;
}
int main() {
   string X="TCGCCTT";
   string Y="GGGGTAACT";
   LongestCommonSubsequence(X,Y);
   return 0;
}

.

Similar Solved Questions

1 answer
In the figure we have: 3 fluids and 3 pistons. Relative Density of the pistons is...
In the figure we have: 3 fluids and 3 pistons. Relative Density of the pistons is 5 and have the following dimensions: Diameter = 20 ??, Thickness = 10 ?? a) Determine: ?1, ?2 and ?3 (at ???). b) Determine: ?4 (in ???). P4 Q GAS P, GAS 0.2 m DR = 1 P20- GAS 0.2 m DR = 2 P3 GAS ई 0.6 m 0.4 m D...
1 answer
If an electron has 8 electrons in its ground state, what is the correct electron configuration for the element?
If an electron has 8 electrons in its ground state, what is the correct electron configuration for the element?...
1 answer
Question 1 5 pts In dynamics, reaction forces are not constant but can change direction. True...
Question 1 5 pts In dynamics, reaction forces are not constant but can change direction. True False Question 2 5 pts What is the difference between a rigid body and a flexible one? O The points on a flexible body do not always remain the same distance from each other. O A flexible body has a nominal...
8 answers
A Science instrutor assigns his student one second of home work
A Science instrutor assigns his student one second of home work..the first week of school,two seconds. the second week four seconds, the third.if the student asked whether he would agree to this weekly homework doubling for the duration of the 36-week school year.how much homework in hours would thi...
3 answers
Can someone tell me the Simularitys and Non-simularitys of these too books Baldwins account of the Titanic and Rosenthal's avvount of his visit to auschwitz, Please and thank you
Can someone tell me the Simularitys and Non-simularitys of these too books Baldwins account of the Titanic and Rosenthal's avvount of his visit to auschwitz, Please and thank you...
1 answer
Given the following data: C(s) + O2(g) → CO2(g) ΔH = -393.5 kJ CS2(l) + 3O2(g) → CO2(g) + 2SO2(g) ΔH = -1076.5 kJ C(s) +...
Given the following data: C(s) + O2(g) → CO2(g) ΔH = -393.5 kJ CS2(l) + 3O2(g) → CO2(g) + 2SO2(g) ΔH = -1076.5 kJ C(s) + 2S(s) → CS2(l) ΔH = +89.4 kJ Find the ΔH of the following reaction: SO2(g) → S(s) + O2(g)...
1 answer
Your aunt is planning to invest in a bank CD that will pay 8.0 percent interest...
Your aunt is planning to invest in a bank CD that will pay 8.0 percent interest semiannually. If she has $10,500 to invest, how much will she have at the end of four years?...
1 answer
Consider the following vector function. r(t) = 5t, ed, e) (a) Find the unit tangent and...
Consider the following vector function. r(t) = 5t, ed, e) (a) Find the unit tangent and unit normal vectors T(t) and N(t). T(t) N(t) (b) Use this formula to find the curvature. k(t) =...
1 answer
The following table shows the average life expectancy, in years, of a child born in the...
The following table shows the average life expectancy, in years, of a child born in the given year Year 2005 2007 2009 2011 2013 Life expectancy 77.6 78.1 78.5 78.7 78.8 If t denotes the time in years since 2005 and E the life expectancy in years, then it turns out that the trend line for these data...
1 answer
The relationship between the factors of production used by a firm and the maximum output possible...
The relationship between the factors of production used by a firm and the maximum output possible is called the O average product. O average total cost. O profit function. O production function. The table shows how Widgets R Us can use different combinations of labor and capital to produce its widge...
1 answer
Calculate the force in each member, stating whether they are in tension or compression: 서1 .Se com 1a.dN 서1 .Se...
Calculate the force in each member, stating whether they are in tension or compression: 서1 .Se com 1a.dN 서1 .Se com 1a.dN...
1 answer
Of 250 candidates writing a exam, 147 passed in math,150 pass in chemistry and 85 pass subjects B)calculate the number of students who pass i)pass math only ii)pass chemistry only iii)passed neither iv)pass only one subject
of 250 candidates writing a exam, 147 passed in math,150 pass in chemistry and 85 pass subjectsB)calculate the number of students who pass i)pass math only ii)pass chemistry only iii)passed neither iv)pass only one subject...
2 answers
Please answer both. The following pertain to the circuit below. What is the equivalent resistance of...
please answer both. The following pertain to the circuit below. What is the equivalent resistance of the circuit? What is the current through R_4? What is the voltage across R_2? Solve for the magnitude and direction of the current in each of the branches of the circuit shown....
1 answer
Discuss with your classmates interview situations you have participated in or heard about that didn't quite...
Discuss with your classmates interview situations you have participated in or heard about that didn't quite work out the way they were supposed to. Give "anonymous" details of the situation only. The purpose is to share and discuss with your classmates some mistakes and problems that can...
1 answer
F(x)=3x^2-2x+1, evaluate f(-1)
f(x)=3x^2-2x+1, evaluate f(-1)...
1 answer
Constants I Periodic Table ▼ Part A An electrochemical cell is based on the following two...
Constants I Periodic Table ▼ Part A An electrochemical cell is based on the following two half-reactions Compute the cell potential at 25 C 0xSn(s) →S?' (ag, 170M) + 2e- Red CIO, (g, 0.160 atm ) + e-→CO, (aq, 155 M...
1 answer
Last year, Hassan’s Madhatter, Inc. had an ROA of 7.4 percent, a profit margin of 14.40...
Last year, Hassan’s Madhatter, Inc. had an ROA of 7.4 percent, a profit margin of 14.40 percent, and sales of $20 million. Calculate Hassan’s Madhatter’s total assets. (Enter your answer in dollars, rounded to the nearest dollar.)...
1 answer
(8 pts) 1. What payment must I invest at the end of each quarter into an...
(8 pts) 1. What payment must I invest at the end of each quarter into an account paying 2.3%/year interest compounded quarterly, if I will need $10,000 in five years? (9 pts) 2. Solve using the modified Gauss-Jordan method, as presented in class 2x+3y + 5z = 2 4x + y - 2=4 2x+y = 3...
1 answer
What is resource debt
What is resource debt...