Cod sursa(job #1011323)

Utilizator MarghescuGabriel Marghescu Marghescu Data 16 octombrie 2013 19:00:19
Problema Subsir crescator maximal Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.79 kb
#include<fstream>
#define nmax 100002
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
int n;
long a[nmax],b[nmax],c[nmax];
void dinamica()
{
    int i,j;
    int lmax=0,pmax=0;
    for(i=n;i>=1;i--)
    {
        int vmax=0,poz=0;
        for(j=i+1;j<=n;j++)
        {
            if(a[i]<a[j] && b[j]>vmax)
            {
                vmax=b[j];
                poz=j;
            }
        }
        b[i]=1+vmax;
        c[i]=poz;
        if(b[i]>lmax)
        {
            lmax=b[i];
            pmax=i;
        }
    }
    g<<lmax<<"\n";
    for(i=pmax;i!=0;i=c[i])
    {
        g<<a[i]<<" ";
    }
}

int main()
{
    f>>n;
    for(int i=1;i<=n;i++)
        f>>a[i];

    dinamica();

    f.close();
    g.close();
    return 0;
}