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 #include #include using namespace std; // LIS[i] stores the maximum length of S's LIS ending at i. void doLIS(const vector &S, vector &LIS) { vector 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 S(N); for (int i = 0; i < N; ++i) cin >> S[i]; vector 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;

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

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 <vector>
#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;
}

Wavio Sequence
Description
Wavio is a sequence of integers. It has some interesting properties.
• Wavio is of odd length i.e., L-2x n + 1.
• The first (n + 1) integers of Wavio sequence makes a strictly increasing sequence.
• The last (n + 1) integers of Wavio sequence makes a strictly decreasing sequence.
• NO two adjacent integers are same in a Wavio sequence.
For example 1, 2, 3, 4, 5, 4, 3, 2, 0 is an Wavio sequence of length 9. But 1, 2, 3, 4, 5, 4, 3, 2, 2 is not a valid Wavio sequence. In this problem. You will be given a sequence of integers. You have to find out t
he length of the longest, Wavio sequence which is a subsequence of the given sequence. Consider, the given sequence as :
1, 2, 3, 2, 1, 2, 3, 4, 3, 2, 1, 5, 4, 1, 2, 3, 2, 2, 1, .
Here the longest Wavio sequence is: 1, 2, 3, 4, 5, 4, 3, 2, 1
Input
The input file contains less than 75 test cases. The description of each test case is given below. Input is terminated by end of file.
Each file starts with a positive integer, N, (1 ≤ N ≤ 10000). In next few lines there will be N integers.
Output
For each set of input print the length of longest Wavio sequence in a line.
Sample Input 1
Sample Output 1
10
9
1 2 3 4 5 4 3 2 1 10
9
19
1
1 2 3 2 1
1 5 4 1 2 3 2 2 1
5
1 2 3 4 5
Transcribed Image Text:Wavio Sequence Description Wavio is a sequence of integers. It has some interesting properties. • Wavio is of odd length i.e., L-2x n + 1. • The first (n + 1) integers of Wavio sequence makes a strictly increasing sequence. • The last (n + 1) integers of Wavio sequence makes a strictly decreasing sequence. • NO two adjacent integers are same in a Wavio sequence. For example 1, 2, 3, 4, 5, 4, 3, 2, 0 is an Wavio sequence of length 9. But 1, 2, 3, 4, 5, 4, 3, 2, 2 is not a valid Wavio sequence. In this problem. You will be given a sequence of integers. You have to find out t he length of the longest, Wavio sequence which is a subsequence of the given sequence. Consider, the given sequence as : 1, 2, 3, 2, 1, 2, 3, 4, 3, 2, 1, 5, 4, 1, 2, 3, 2, 2, 1, . Here the longest Wavio sequence is: 1, 2, 3, 4, 5, 4, 3, 2, 1 Input The input file contains less than 75 test cases. The description of each test case is given below. Input is terminated by end of file. Each file starts with a positive integer, N, (1 ≤ N ≤ 10000). In next few lines there will be N integers. Output For each set of input print the length of longest Wavio sequence in a line. Sample Input 1 Sample Output 1 10 9 1 2 3 4 5 4 3 2 1 10 9 19 1 1 2 3 2 1 1 5 4 1 2 3 2 2 1 5 1 2 3 4 5
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY