Cod sursa(job #1013982)

Utilizator AllxCucuCucu Alexandru AllxCucu Data 21 octombrie 2013 22:40:23
Problema Subsir crescator maximal Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.73 kb
#include <fstream>
			 using namespace std;
ifstream f ("scmax.in");
ofstream g ("scmax.out");
int stare[100003];
int a[100003]
int max,sol=0,p;
int poz[100003];
int n;
void citeste()
  {
f>>n;
	for(int i=1;i<=n;++i) f>>a[i];
  }
void dinamic()
  {
  int i,j;
  stare[n]=1;
  poz[n]=-1;
  max=1;
  p=n;
  for(i=n-1; i>=1; i--)
	{
	stare[i]=1;
	poz[i]=-1;
	for(j=i+1; j<=n; j++)
		 if(a[i]<a[j] && stare[i]<stare[j]+1)
			{
			stare[i]=stare[j]+1;
			poz[i]=j;
			if(stare[i]>max)
			{
			max=stare[i];
			p=i;
			}
			}
	}
  }
void constr()
  {
  int i;
  i=p;
  while(i!=-1)
	{
g<<a[i];
	i=poz[i];
	}
  }
int main()
  {
  citeste();
  dinamic();
g<<'\n'<<max);
  constr();
  return 0;
  }