Cod sursa(job #572074)

Utilizator M_ZsoltMezei Zsolt M_Zsolt Data 4 aprilie 2011 23:48:02
Problema Subsir crescator maximal Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.7 kb
#include<fstream>
//#include<iostream>

using namespace std;

int main(){
	long n;
	long *a;
	a=new long[100000];
	int *poz;
	poz=new int[100000];
	int h[100000];
	int i;
	fstream f;
	f.open("scmax.in",ios::in);
	f>>n;
	for(i=0;i<n;i++)
		f>>a[i];
	f.close();
	h[n-1]=1;
	poz[n-1]=-1;
	for(i=n-2;i>=0;i--){
		h[i]=1;
		poz[i]=-1;
		for(int j=i+1;j<n;j++)
			if(a[i]<a[j] && h[i]<1+h[j]){
				h[i]=1+h[j];
				poz[i]=j;
			}
	}
	f.open("scmax.out",ios::out);
	int pozmax=0,max=h[0];
	for(i=1;i<n;i++)
		if(max<h[i]){
			max=h[i];
			pozmax=i;
		}
	f<<max<<'\n';
	//cout<<max<<'\n';
	i=pozmax;
	while(i!=-1){
		f<<a[i]<<" ";
		//cout<<a[i]<<" ";
		i=poz[i];
	}
	f.close();
}