Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int n;
- int v[1000], poz[1000], maxi, poz2;
- vector <int> dp(1000, 1);
- void display(int p)
- {
- if (p == 0)
- return;
- display(poz[p]);
- cout << v[p] << ' ';
- }
- int main()
- {
- cin >> n;
- for (int i = 1; i <= n; i++)
- cin >> v[i];
- for (int j = 2; j <= n; j++)
- {
- for (int i = 1; i < j; i++)
- if (v[j] >= v[i])
- {
- dp[j] = dp[i] + 1;
- poz[j] = i;
- }
- }
- /* for (int i = 1; i <= n; i++)
- cout << poz[i] << ' ';
- cout<<endl;//*/
- for (int i = 1; i <= n; i++)
- {
- if (dp[i] > maxi)
- {
- maxi = dp[i];
- poz2 = i;
- }
- }
- display(poz2);//*/
- //cout << poz2;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement