Cod sursa(job #1045148)

Utilizator Corina1997Todoran Ana-Corina Corina1997 Data 30 noiembrie 2013 22:35:30
Problema Subsir crescator maximal Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.76 kb
#include <vector>
#include <fstream>
using namespace std;

ifstream is("scmax.in");
ofstream os("scmax.out");

int n, lmax, pmax;
vector<long long int> a, L, t;

void Path( int i );

int main()
{
    is >> n;
    a.resize( n + 1);
    L.resize( n + 1);
    t.resize( n + 1);
    for ( int i = 1; i <= n; i++ )
    {
        is >> a[i];
        L[i] = 1;
        for ( int j = 1; j < i; j++ )
            if ( L[i] < L[j] + 1 && a[i] > a[j] )
                L[i] = L[j] + 1, t[i] = j;
        if ( L[i] > lmax )
            lmax = L[i], pmax = i;
    }
    os << lmax << '\n';
    Path( pmax );

    is.close();
    os.close();
    return 0;
}

void Path( int i )
{
    if ( i == 0 ) return;
    Path( t[i] );
    os << a[i] << ' ';
}