Cod sursa(job #1464761)

Utilizator Vlad_lsc2008Lungu Vlad Vlad_lsc2008 Data 24 iulie 2015 15:35:39
Problema Subsir crescator maximal Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.87 kb
#include <iostream>
#include <fstream>
#define fin "scmax.in"
#define fou "scmax.out"
using namespace std;
ifstream t1(fin);
ofstream t2(fou);
int n,prec[100010],best[100010],maxim,pozmax;
long sir[100010];

int main()
{
    int i,j;
    t1>>n;
    for(i=1;i<=n;i++) t1>>sir[i];
    best[n]=1; prec[n]=0; maxim=1;
    for(i=n-1;i>=1;i--)
        for(j=i+1;j<=n;j++)
            if(best[j]>best[i] && sir[j]>sir[i])
            {
                best[i]=best[j]+1;
                prec[i]=j;
                if(best[i]>maxim)
                    {
                        maxim=best[i];
                        pozmax=i;
                    }
            }
    t2<<maxim<<'\n';
    while(prec[pozmax])
    {
        t2<<sir[pozmax]<<' ';
        pozmax=prec[pozmax];
    }
    t2<<sir[pozmax]<<'\n';;
    t1.close();
    t2.close();
    return 0;
}