Cod sursa(job #2044310)

Utilizator Cristi_ChiraChira Cristian Cristi_Chira Data 21 octombrie 2017 09:22:06
Problema Jocul Flip Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <fstream>
#define dm 100005
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");

int n,a[dm],best[dm],poz[dm],maxx;

void Afis(int k)
{
    if(poz[k]!=0)
        Afis(poz[k]);

    fout<<a[k]<<" ";
}


int main()
{
   fin >> n;
   for(int i = 1 ;i <= n; ++i)
    fin >> a[i];
   best[1] = 1; poz[1] = 0;

   for(int i = 2;i <= n; ++i)
   {
       best[i] = 1; poz[i] = 0;
       for(int j = 1;j <= i-1; ++j)
         if( a[j] < a[i] && best[i] < best[j] + 1 )
         {
           best[i] = best[j] + 1;
           poz[i] = j;
         }

   }
    maxx = 1;
    for(int i = 2;i <= n; ++i)
        if(best[i] > best[maxx])
            maxx = i;
    fout << best[maxx] << "\n";
    Afis(maxx);

   return 0;
}