Pagini recente » Cod sursa (job #2624301) | Cod sursa (job #1145701) | Cod sursa (job #709162) | Cod sursa (job #428129) | Cod sursa (job #1667860)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("scmax.in");
ofstream s("scmax.out");
const int N = 100001;
int v[N] ,lung[N], pred[N];
void sir(int p){
if(pred[p] != 0)sir(pred[p]);
s<<v[p]<<" ";
}
int main()
{
int n,i,j,lmax,tmax=0;
f>>n;
for(i=0; i<n; i++)
f>>v[i];
lung[0] = 1;
pred[0] = 0;
for(i=1; i<n; i++)
{
lmax = 0;
pred[0] = 0;
for(j=i-1; j>=0; j--)
if (v[j] < v[i])
if (lung[j] > lmax)
{
lmax = lung[j];
pred[i] = j;
}
lung[i] = 1 + lmax;
if(lung[i]>lung[tmax])
tmax = i;
}
s<<v[tmax]<<" "<<endl;
sir(tmax);
return 0;
}