Pagini recente » Cod sursa (job #583004) | Cod sursa (job #3358158) | Cod sursa (job #652039) | Cod sursa (job #1546581) | Cod sursa (job #3339424)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("scmax.in");
ofstream fout("scmax.out");
int n, maxi, lmax, v[100010], t[100010], dp[100010], p, q;
void drum(int u) {
if (u) {
drum(t[u]);
cout << v[u] << " ";
}
}
int main () {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> v[i];
dp[1] = 1;
for (int i = 2; i <= n; i++) {
maxi = 0;
for (int j = 1; j < i; j++)
if (v[j] < v[i] && dp[j] > maxi) {
maxi = dp[j];
p = j;
}
dp[i] = maxi + 1;
if (dp[i] != 1) t[i] = p;
else t[i] = 0;
if (dp[i] > lmax) {
lmax = dp[i];
q = i;
}
}
cout << lmax;
drum(q);
return 0;
}