Cod sursa(job #1686107)

Utilizator AlexandruX1Ureche Florin Alexandru AlexandruX1 Data 12 aprilie 2016 08:20:19
Problema Subsir crescator maximal Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.67 kb
#include <iostream>
#include <fstream>

using namespace std;

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

const int NR = 100000;
int a[NR], l[NR], t[NR], n, f, Lmax;

void Rec (int ind)
{
    if (ind == 0) return;
    Rec (t[ind]);

    fout << a[ind] <<" ";

}

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

    for (int i = 1; i <= n; i ++)
    for (int j = 1; j < i; j ++)
    if (l[j] >= l[i] && a[j] < a[i])
        {
            l[i] = l[j] + 1;
            t[i] = j;
            f = i;

            Lmax = max(l[i], Lmax);
        }

    fout << Lmax <<"\n";
    Rec(f);

    return 0;
}