Cod sursa(job #2098013)

Utilizator manu18Buza Gregor manu18 Data 2 ianuarie 2018 00:39:37
Problema Subsir crescator maximal Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.13 kb
//
//  main.cpp
//  tema tap programare dinamica ex 1
//
//  Created by Buza Gregor Emanuel on 01/01/2018.
//  Copyright © 2018 Buza Gregor Emanuel. All rights reserved.
//

#include <iostream>
#include<fstream>
#include<vector>
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
int n,buf,i,prec[1000],best[1000],x[100],j;
void afisare(int k)
{
    if(prec[k]==-19)
        g<<x[k]<<" ";
    else{
    afisare(prec[k]);
    g<<x[k]<<" ";
    }
}
int main(int argc, const char * argv[]) {
    
    
    f>>n;
   
    for(i=0;i<n;i++)
    {
        f>>x[i];
        prec[i]=-19;
    }
    int best1,max;
    for(i=1;i<n;i++)
    {
        max=1;
        best1=1;
        
        for(j=0;j<i;j++)
            if(x[i]>x[j])
            {
                best1=best[j]+1;
                if(best1>max)
                {
                    max=best1;
                    prec[i]=j;
                }
            }
        best[i]=max;
    }
  
    
    max=-100;
    int k=0;
 
    for(i=0;i<n;i++)
        if(best[i]>max)
        {
            max=best[i];
            k=i;
        }
    g<<max<<"\n";
    afisare(k);
   
    return 0;
}