Cod sursa(job #1744204)

Utilizator xSliveSergiu xSlive Data 19 august 2016 14:21:34
Problema Subsir crescator maximal Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.92 kb
#include <iostream>
#include <fstream>
#define NMAX 100010
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
unsigned long long v[NMAX];
unsigned long long pre[NMAX];
unsigned long long cost[NMAX];
unsigned int n;

void apeleazaRec(int poz,int len){
    if(poz!=-1){
        apeleazaRec(pre[poz],len+1);
        g << v[poz] << ' ';
    }
    else g << len << '\n';
}

void rezolva(){
    f >> n;
    for(unsigned int i=0;i<n;i++) {  f >> v[i]; cost[i]=1; pre[i]=-1;}
    for(int i=1;i<n;i++)
        for(int j=0;j<i;j++)
            if(v[i] > v[j] && cost[i] < cost[j]+1){
                cost[i] = cost[j]+1;
                pre[i] = j;
            }
    int maxim = cost[0];
    int poz=0;
    for(int i=1;i<n;i++)
        if(maxim < cost[i]){
            maxim = cost[i];
            poz=i;
        }
    apeleazaRec(poz,0);
}

int main()
{
    rezolva();
    return 0;
}