Please explain Wavio Sequencing more clearly for me please there's a picture of the decription and also comment on the code below to know what each line is doing. It is in C++
#include <iostream>
#include <
#include <algorithm>
using namespace std;
// LIS[i] stores the maximum length of S's LIS ending at i.
void doLIS(const vector<size_t> &S, vector<size_t> &LIS)
{
vector<size_t> L(S.size());
size_t lisCount = 0;
for (size_t i = 0; i < S.size(); ++i)
{
size_t pos = lower_bound(L.begin(), L.begin() + lisCount, S[i])
- L.begin();
L[pos] = S[i];
if (pos == lisCount)
++lisCount;
LIS[i] = pos + 1;
}
}
int main()
{
size_t N;
while (cin >> N)
{
vector<size_t> S(N);
for (int i = 0; i < N; ++i)
cin >> S[i];
vector<size_t> LIS(N), LDS(N);
doLIS(S, LIS);
reverse(S.begin(), S.end());
doLIS(S, LDS);
reverse(LDS.begin(), LDS.end());
size_t maxLIS = 0;
for (size_t i = 0; i < LIS.size(); ++i)
{
/** Suppose S[] = 1 3 6 5
LIS[] = 1 2 3 3
LDS[] = 1 1 2 1
then we can pick 1 6 5 or 3 6 5.
*/
maxLIS = max(maxLIS, 2 * min(LIS[i], LDS[i]) - 1);
}
cout << maxLIS << endl;
}
return 0;
}
Step by stepSolved in 2 steps
- Questions: There needs to be a dynamic array of Child that opposes with SCALE and is assigned to "familyTree". The createFamilyTree() function needs to be defined. Please see the C++ code.arrow_forwardC++ Dynamic Array Project Part 2arrow_forwardSelect all code lines that creates a vector with content {10, 10, 10, 10). You are also given the C-type array, an_array with content (10, 10, 10, 10). std::vector a_vector (an_array, an_array + sizeof(an_array)/sizeof(int)); std::vector a_vector [10, 10, 10, 10); std::vector a_vector (10, 4); std::vector a_vector = {10, 10, 10, 10); Ostd::vector a_vector (4, 10);arrow_forward
- Answer in C++ code please! (Duplicate Elimination with vector) Use a vector to solve the following problem. Read in 20 numbers, each of which is between 10 and 100, inclusive. As each number is read, validate it and store it in the vector only if it isn't a duplicate of a number already read. After reading all the values, display only the unique values that the user entered. Begin with an empty vector and use its push_back function to add each unique value to the vector.arrow_forwardplease help me with codingarrow_forwardComplete the C++ code below#include "std_lib_facilities.h"/*1. Define a function which calculates the outer product of two vectors. The function return is a matrix. */vector<vector<int>> outerProduct(vector<int>& A, vector<int>& B){//implement here}/*2. Define a function which transposes a matrix. */vector<vector<int>> transpose(vector<vector<int>>& A){//implementation}/*3. Define a function which calculates the multiplication of a matrix and it's transpose. */vector<vector<int>> product(vector<vector<int>>& A){// implementation}/*4. Define a print out function that will print out a matrix in the following format:Example: a 3 by 4 matrix should have the print out:1 2 3 42 3 4 53 4 5 6*/void printMatrix(vector<vector<int>>& A){// implementation}int main(){// Define both vector A and vector Bvector<int> A = {1 ,2, 3, 4, 5};vector<int> B = {1, 2, 3};/*Test outerProduct…arrow_forward
- need help in C++ Problem: You are asked to create a program for storing the catalog of movies at a DVD store using functions, files, and user-defined structures. The program should let the user read the movie through the file, add, remove, and output movies to the file. For this assignment, you must store the information about the movies in the catalog using a single vector. The vector's data type is a user-defined structure that you must define on functions.h following these rules: Identifier for the user-define structure: movie. Member variables of the structure "movie": name (string), year (int), and genre (string). Note: you must use the identifiers presented before when defining the user-defined structure. Your solution will NOT pass the unit test cases if you do not follow the instructions presented above. The main function is provided (you need to modify the code of the main function to call the user-defined functions described below). The following user-defined functions are…arrow_forwardIn C++ Assume that a 5 element array of type string named boroughs has been declared and initialized. Write the code necessary to switch (exchange) the values of the first and last elements of the array.arrow_forwardUsing C++ Language Need help on below code, I have the code but need to compute maximum of the array. Code: #include<iostream> using namespace std; int main() { int size; cout<<" Enter array size: "; cin>>size; int *numList=new int[size]; cout<<"Enter "<<size<<" elements: "; for(int i=0;i<size;i++) { cin>> *(numList+i); } delete numList; return 0; }arrow_forward
- You may use the vector and iostream libraries. You are allowed to use three built-in vector member functions (and no others) but you may not have to use them all. The member functions you are allowed to use are size(), at(), and push_back() Write a function that outputs a vector of doubles with each number in the vector separated by a space then a newline after the entire vector is output. The whole vector output should be preceded by a single line saying "Current Vector Contents:". Write a function that takes a vector a doubles and reverses the order of all the elements of the vector. Write a function that fills a vector of doubles with positive numbers using the standard input stream cin, terminate the input when the user enters any negative number. A single output prompt should precede the initial input stating directions for user. Write a main function that creates an empty vector, calls functions from 2 & 3 and calls your output function before and after each of your calls…arrow_forwardThe whole question is included in the picture with the output please help...arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY