Cod sursa(job #1502409)

Utilizator VentuAndreiVentunandrei VentuAndrei Data 14 octombrie 2015 17:06:25
Problema Subsir crescator maximal Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.78 kb
#include <bits/stdc++.h>

using namespace std;
const int nmax = 100005;
ifstream f("scmax.in");
ofstream g("scmax.out");

int v[nmax], best[nmax], poz[nmax], p;

int main()
{

  int n,i,nr=0,j, maxx=0;

  f >> n ;

  for(i = 1; i <= n; i++)
  {
      f >> v[i];
  }

  best[n]= 1;
  poz[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;
              poz[i] = j ;
              if(best[i] > maxx)
              {
                  maxx=best[i];
                  p=i;
              }


          }


      }

  }

  g<<best[p]<<"\n";

  while(p!=-1)
  {
      g<<v[p]<<" ";
      p=poz[p];
  }
    return 0;
}