Cod sursa(job #858676)

Utilizator rares123Zamfiriu Rares rares123 Data 19 ianuarie 2013 10:23:02
Problema Subsir crescator maximal Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.9 kb
#include <iostream>
#include <fstream.h>
using namespace std;

int a[10],lg[10];

int main()
{
    ifstream fin ("scmax.in");
    ofstream fout ("scmax.out");
    int n,i,j,max;
    fin >> n;
    for (i=0;i<n;i++)
        fin >> a[i];
    lg [n-1]=1;
    for (i=n-2;i>=0;i--)
        {
            max=0;
            for (j=i+1;j<n;j++)
                if (lg[j]>max && (a[j] > a[i]))
                    max=lg[j];
            lg[i]=max+1;

        }
    max=0;
    int x;
    for (i=0;i<n;i++)
        if (lg[i]>max)
            {
                max=lg[i];
                x=i;
            }
    cout << lg[x] << endl;
    cout << a[x] << " ";
    while (max)
    {
        for (j=x+1;j<n;j++)
            if (lg[j]==max-1 && a[j]>a[x])
                {
                    x=j;
                    cout << a[j] << " ";
                }
        max--;
    }
    return 0;
}