Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- #define NMAX 1003
- int n, v[NMAX], best[NMAX], p[NMAX], maxLen, maxPos;
- void write(int pos) {
- if (pos) {
- write(p[pos]);
- cout << v[pos] << ' ';
- }
- }
- int main() {
- cin >> n;
- for (int i = 1; i <= n; i++) {
- cin >> v[i];
- best[i] = 1;
- }
- for (int i = 1; i <= n; i++) {
- for (int j = i - 1; j; j--) {
- if (v[i] > v[j] && best[i] < best[j] + 1) {
- best[i] = best[j] + 1;
- p[i] = j;
- }
- }
- }
- for (int i = 1; i <= n; i++)
- if (maxLen < best[i]) {
- maxLen = best[i];
- maxPos = i;
- }
- cout << maxLen << endl;
- write(maxPos);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement