Pagini recente » Cod sursa (job #953872) | Cod sursa (job #1527542) | Cod sursa (job #694286) | Cod sursa (job #1397546) | Cod sursa (job #2478072)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("cmlsc.in");
ofstream fout ("cmlsc.out");
const int N = 100005;
int a[N], best[N], dad[N];
void path(int k)
{
if(dad[k] != 0) path(dad[k]);
fout << a[k] << " ";
}
int main()
{
ios::sync_with_stdio(false);
fin.tie(0);
int n, m;
int mx = 0, pos = -1;
fin >> n;
for(int i = 1; i <= n; ++i) fin >> a[i];
for(int i = 1; i <= n; ++i) {
for(int j = 1; j < i; ++j) {
if(a[i] > a[j] && best[j] + 1 > best[i]) best[i] = best[j] + 1, dad[i] = j;
}
if(best[i] > mx) pos = i;
mx = max(mx, best[i]);
}
fout << best[pos] + 1 << "\n";
path(pos);
return 0;
}