Cod sursa(job #1648002)

Utilizator secretCCMniciun nume secretCCM Data 10 martie 2016 23:21:48
Problema Subsir crescator maximal Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.72 kb
#include <iostream>
#include <fstream>

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

const int Nmax = 100005;
int n, a[Nmax], DP[Nmax], pos[Nmax], Max, poz;

int main()
{
    f>>n;
    for(int i = 1; i <= n; i++) f>>a[i];
    for(int i = n; i > 0; i--)
    {
        DP[i] = 1;
        for(int j = i+1; j <= n; j++)
        {
            if(a[i] < a[j] && DP[i] < DP[j] + 1)
            {
                DP[i] = DP[j] + 1;
                pos[i] = j;
            }
        }
        if(Max < DP[i])
        {
            Max = DP[i];
            poz = i;
        }
    }
    g<<Max<<'\n';
    for(int i = poz; i > 0; i = pos[i]) g<<a[i]<<' ';
    g<<'\n';
    return 0;
}