Pagini recente » Cod sursa (job #2552878) | Cod sursa (job #389391) | Cod sursa (job #2167388) | Cod sursa (job #1660911) | Cod sursa (job #1966230)
#include <fstream>
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
#define nmax 100005
int n, v[nmax], best[nmax], nxt[nmax], lmax, first;
void citire()
{
int i;
fin>>n;
for(i=1; i<=n; i++)
fin>>v[i];
fin.close();
}
void dinamica()
{
int i, j, mx, poz=0;
lmax=1;
for(i=n; i>=1; i--)
{
best[i]=1;
mx=0;
for(j=i+1; j<=n; j++)
if(v[i]<v[j])
if(best[j]>mx)
{
mx=best[j];
poz=j;
}
best[i]=1+mx;
nxt[i]=poz;
if(best[i]>lmax)
{
lmax=best[i];
first=i;
}
}
}
void afisare()
{
int i;
fout<<lmax<<'\n';
for(i=first; i!=0; i=nxt[i])
fout<<v[i]<<' ';
fout<<'\n';
fout.close();
}
int main()
{
citire();
dinamica();
afisare();
return 0;
}