Pagini recente » Cod sursa (job #3236892) | Cod sursa (job #2769898) | Cod sursa (job #2669431) | Cod sursa (job #103019) | Cod sursa (job #1996619)
#include <bits/stdc++.h>
using namespace std;
int n, v[105], lis[105], next[105], maxim, poz;
int main()
{
freopen("scmax.in", "r", stdin);
freopen("scmax.out", "w", stdout);
scanf("%d", &n);
for(int i = 1; i <= n; ++i) scanf("%d", &v[i]);
lis[n] = 1; next[n] = n + 1;
for(int i = n - 1; i >= 1; --i)
{
maxim = 0;
poz = n + 1;
for(int j = i + 1; j <= n; ++j)
if(v[i] < v[j] && lis[j] > maxim)
{
maxim = lis[j];
poz = j;
}
lis[i] = 1 + maxim;
next[i] = poz;
}
maxim = lis[1]; poz = 1;
for(int i = 2; i <= n; ++i)
if(lis[i] > maxim)
{
maxim = lis[i];
poz = i;
}
printf("%d\n", maxim);
while(poz != n + 1)
{
printf("%d ", v[poz]);
poz = next[poz];
}
return 0;
}