Advertisement
STANAANDREY

lis

Mar 21st, 2019
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int v[1000],n,i;
  8.     cout<<"n=";cin>>n;
  9.     for (i=0;i<n;i++)
  10.    {
  11.        cout<<"v["<<i<<"]=";cin>>v[i];
  12.    }
  13. vector<vector<int> > L(n);
  14.     L[0].push_back(v[0]);
  15.     for (int i = 1; i < n; i++)
  16.     {
  17.         for (int j = 0; j < i; j++)
  18.         {
  19.             if ((v[i] > v[j]) &&(L[i].size() < L[j].size() + 1))
  20.                 L[i] = L[j];
  21.         }
  22.         L[i].push_back(v[i]);
  23.     }
  24.     vector<int> maxi = L[0];
  25.     for (vector<int> x : L)
  26.         if (x.size() > maxi.size())
  27.             maxi = x;
  28.     for (auto x : maxi)
  29.         cout << x << " ";
  30.     cout << endl;
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement