Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin("file.in");
- ofstream fout("file.out");
- #define NMAX 100005
- int v[NMAX], n, maxi, dp[NMAX], poz[NMAX], poz2;
- void Read()
- {
- fin >> n;
- for (int i = 1; i <= n; i++)
- fin >> v[i];
- }
- void display(int p)
- {
- if (!p)
- return;
- display(poz[p]);
- fout << v[p] << ' ';
- }
- int main()
- {
- Read();
- for (int i = 1; i <= n; i++)
- {
- dp[i] = 1;
- for (int j = i - 1; j; j--)
- if (v[j] < v[i])
- {
- if (dp[i] < dp[j] + 1)
- {
- dp[i] = dp[j] + 1;
- poz[i] = j;
- }
- }
- }
- for (int i = 1; i <= n; i++)
- cout << dp[i]<<' ';
- for (int i = 1; i <= n; i++)
- {
- if (dp[i] > maxi)
- {
- maxi = dp[i];
- poz2 = i;
- }
- }
- fout << maxi << '\n';
- display(poz2);
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement