Pagini recente » Cod sursa (job #70406) | Cod sursa (job #978851) | Cod sursa (job #2919341) | Cod sursa (job #2552698) | Cod sursa (job #2119140)
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
using namespace std;
const int N = 100001;
int v[N], pred[N], dp[N];
ifstream fin ("scmax.in");
ofstream fout ("scmax.out");
void subsir ( int p )
{
if ( pred[p] != 0 )
{
subsir ( pred[p] );
}
fout << v[p] << " ";
}
int main()
{
int pmax = 1, n;
fin >> n;
for ( int i = 1 ; i <= n ; i++ )
fin >> v[i];
for ( int i = 1 ; i <= n; i++ )
{
int lmax = 0;
for ( int j = 1 ; j < i ; j ++ )
{
if ( v[j] < v[i] )
{
if ( dp[j] > lmax )
{
lmax = dp[j];
pred[i] = j;
}
}
}
dp[i] = 1 + lmax;
if ( dp[i] > dp[pmax] )
{
pmax = i;
}
}
fout << dp[pmax] <<"\n";
subsir ( pmax );
return 0;
}