Cod sursa(job #658695)

Utilizator razvan_kusztosKusztos razvan razvan_kusztos Data 9 ianuarie 2012 12:57:33
Problema Subsir crescator maximal Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.87 kb
#include<cstdio>
#define l 100003
using namespace std;
int a[l],poz[l],best[l],j,i,n,max,p;
int main()
    {
        freopen("scmax.in","r",stdin);
        freopen("scmax.out","w",stdout);
        scanf("%d",&n);
        for (i=1 ;i<=n;i++) scanf("%d",&a[i]);
        best[n]=1;
        poz[n]=-1;
        for (i=n-1;i>=1;i--)
            {
                best[i]=1;
                poz[i]=-1;
                for (j=i+1;j<=n;j++)
                        if (a[i]<a[j]&& best[i]<best[j]+1)
                        {
                            best[i]=best[j]+1;
                            poz[i]=j;
                            if (best[i]>max) { max=best[i]; p=i; }
                        }
            }
        printf("%d\n",max);
        while(p!=-1)
             {
                 printf("%d ",a[p]);
                 p=poz[p];
             }
    }