Cod sursa(job #2720922)

Utilizator dumitrustefaniaDumitru Stefania dumitrustefania Data 11 martie 2021 13:35:02
Problema Subsir crescator maximal Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.86 kb

#include <bits/stdc++.h>
#include <cstring>
# define pb push_back
#define nmax 100002
using namespace std;
ifstream in("scmax.in");
ofstream out("scmax.out");
string a,b;
int ok,k,i,n,best[nmax],j,max1,urm[nmax],p,poz,v[nmax],nr;

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

    best[n]=1;
    for(i=n-1; i>=1; i--)
        for(j=i+1; j<=n; j++)
            if(v[i]<v[j]&&best[i]<best[j]+1)
            {
                best[i]=best[j]+1;
                if(best[i]>max1)
                {
                    max1=best[i];
                    poz=i;
                }
                urm[i]=j;
            }

    p=poz;
     while(poz)
     {
         nr++;
         poz=urm[poz];
     }
     out<<nr<<"\n";

     poz=p;
    while(poz)
    {
        out<<v[poz]<<" ";
        poz=urm[poz];
    }
    return 0;
}