Cod sursa(job #909009)

Utilizator MIonutMistreanu Ionut MIonut Data 10 martie 2013 13:56:14
Problema Subsir crescator maximal Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.87 kb
#include<fstream>
#include<vector>
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
vector<int>v;
vector<int>best;
vector<int>poz;
int n,dmin=1,pf;
void citire(){
    f>>n;
    v.push_back(0);
    best.push_back(1);
    poz.push_back(0);
    for(int x, i=1; i<=n; ++i){
        f>>x;
        v.push_back(x);
        best.push_back(1);
        poz.push_back(0);
    }
}
void parcurgere(){
    for(int i=2; i<=n; ++i){
        for(int j=1; j<i; ++j)
            if(v[i]>v[j] && best[i]<best[j]+1){
                best[i]=1+best[j];
                poz[i]=j;
            }
        if(best[i]>dmin) { dmin=best[i]; pf=i;}
    }
    g<<dmin<<"\n";
}
void afisare(int i){
    if(poz[i]==0) g<<v[i]<<" ";
    else if(poz[i]>0){
        afisare(poz[i]);
        g<<v[i]<<" ";
    }
}
int main(){
    citire();
    parcurgere();
    afisare(pf);
return 0;
}