Pagini recente » Cod sursa (job #2892229) | Cod sursa (job #935475) | Cod sursa (job #1604682) | Cod sursa (job #1386881) | Cod sursa (job #3195646)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
int main()
{
int n;
f >> n;
int v[n+1];
int d[n+1];
int poz[n+1];
int dmax = 0, pozdmax;
d[0] = 0;
poz[0] = 0;
for( int i = 1; i <= n; ++i )
{
f >> v[i];
int lmax = 0, ind;
for( int j = i-1; j >= 0; --j )
{
if( v[j] < v[i] && d[j] > lmax )
{
lmax = d[j];
ind = j;
}
}
d[i] = lmax+1;
poz[i] = ind;
if( dmax < d[i] )
{
dmax = d[i];
pozdmax = i;
}
}
int l = pozdmax;
g << lmax << endl;
while( l != 0 )
{
g << v[ l ]<< " ";
l = poz[ l ];
}
return 0;
}