Cod sursa(job #1790713)

Utilizator blackmanta45Andrei blackmanta45 Data 28 octombrie 2016 17:24:46
Problema Subsir crescator maximal Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.69 kb
#include <fstream>
#define DIM 100010
using namespace std;
ifstream fin ("scmax.in");
ofstream fout ("scmax.out");
int v[DIM],L[DIM],i,j,ant[DIM],poz,maxim,n;

void afisare (int poz, int ant[]){
    if(poz!=0){
        afisare (ant[poz],ant);
        fout<<v[poz]<<" ";
    }
}

int main () {
    fin>>n;
    for(i=1;i<=n;i++)
        fin>>v[i];
    for(i=1;i<=n;i++){
        L[i]=1;
        for(j=1;j<i;j++){
            if(v[j]<v[i] && L[j]+1>L[i]){
                ant[i]=j;
                L[i]=L[j]+1;
                if(L[i]>maxim){
                    maxim=L[i];
                    poz=i;
                }
            }
        }
    }

    afisare (poz,ant);
}