Cod sursa(job #232626)

Utilizator sorecau_catalinSorecau Catalin sorecau_catalin Data 15 decembrie 2008 21:22:49
Problema Subsir crescator maximal Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1.03 kb
#include <fstream.h>

const int DIM = 100000;

ifstream fin  ("scmax.in");
ofstream fout ("scmax.out");

int a[DIM];
int L[DIM];   
int t[DIM];   
int n;
int Lmax;     

void Read ();
void SCLM ();
void Write ();
void Write (int i);

int main ()
{
    Read ();
    SCLM ();
    Write ();
    
    fin.close();
    fout.close();
    return 0;
}    

void Read ()
{
    fin >> n;
    for (int i = 1; i <= n; i++)
        fin >> a[i];
}

void SCLM ()
{
    for (int i = 1; i <= n; i++)
    {
        L[i] = 1;
        t[i] = 0;
        for (int j = 1; j < i; j++)
            if (a[j] < a[i] && L[i] < L[j] + 1)
            {
                L[i] = L[j] + 1;
                t[i] = j;
            }
     } 
 }           

void Write(int i)
{
    if ( !i ) return;
    Write ( t[i]);
    fout << a[i] << " ";
}    

 void Write ()
 {
    int c;
    for (int i = 1; i <= n; i++)
        if (Lmax < L[i])
            Lmax = L[c=i];
    
        
    fout << Lmax << "\n";;
    Write (c);
}