Pagini recente » Cod sursa (job #2271711) | Cod sursa (job #59218) | Cod sursa (job #718684)
Cod sursa(job #718684)
#include<fstream>
#define nmax 100003
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
int v[nmax], i, j, a[nmax],n,m,last[nmax],lmax;
void read()
{
fin >> n ;
for( i = 1; i <= n; i++ )
fin >> v[i];
a[ n ] = 1;
for( i = n; i > 0; i-- )
{
for( j = n ; j > i ; j-- )
{
if(v[i] < v[j] && a[i] < a[j] + 1 )
{
a[i] = a[j] + 1;
last[i] = j;
}
}
}
for( i = 1; i <= n; i++)
if(a[i] > lmax)
{
j = i;
lmax = a[i];
}
fout << lmax << '\n' ;
for ( i = 1; i <= lmax; i++ )
{
fout << v[ j ] << " " ;
j = last[j] ;
}
}
int main()
{
read();
fin.close();
fout.close();
return 0;
}