Pagini recente » Cod sursa (job #683092) | Cod sursa (job #1145336) | Cod sursa (job #832457) | Cod sursa (job #999087) | Cod sursa (job #1648002)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
const int Nmax = 100005;
int n, a[Nmax], DP[Nmax], pos[Nmax], Max, poz;
int main()
{
f>>n;
for(int i = 1; i <= n; i++) f>>a[i];
for(int i = n; i > 0; i--)
{
DP[i] = 1;
for(int j = i+1; j <= n; j++)
{
if(a[i] < a[j] && DP[i] < DP[j] + 1)
{
DP[i] = DP[j] + 1;
pos[i] = j;
}
}
if(Max < DP[i])
{
Max = DP[i];
poz = i;
}
}
g<<Max<<'\n';
for(int i = poz; i > 0; i = pos[i]) g<<a[i]<<' ';
g<<'\n';
return 0;
}