Pagini recente » Cod sursa (job #864958) | Monitorul de evaluare | Cod sursa (job #2288274) | Cod sursa (job #1441158) | Cod sursa (job #1502409)
#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;
}