Cod sursa(job #762890)

Utilizator vendettaSalajan Razvan vendetta Data 30 iunie 2012 14:31:29
Problema Subsir crescator maximal Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.88 kb
#include <iostream>
#include <fstream>

using namespace std;

#define nmax 100005

ifstream f("scmax.in");
ofstream g("scmax.out");

int n, a[nmax], bst[nmax], t[nmax];

void citeste(){

    f >> n;
    for(int i=1; i<=n; i++) f >> a[i];

}

void drum(int x){

    if (t[x])drum(t[x]);
    g << a[x] << " ";

}

void rezolva(){

    int Max = 0;
    int poz = 0;

    for(int i=1; i<=n; i++){
        bst[i] = 1;
        for(int j=1; j<i; j++){
            if (a[i] > a[j] && bst[i] < bst[j]+1){//daca a[i] mai mare ca a[j] si daca pot continua un sir mai lung ca cel din i de pana acum
                bst[i] = bst[j]+1;
                t[i] = j;
            }
        }
        if (bst[i] > Max) Max = bst[i], poz = i;
    }

    g << Max << "\n";
    drum(poz);

}

int main(){

    citeste();
    rezolva();

    f.close();
    g.close();

}