Pagini recente » Cod sursa (job #3157843) | Cod sursa (job #2004463) | Cod sursa (job #1511223) | Cod sursa (job #1287750) | Cod sursa (job #2287952)
#include<cstdio>
const int MAX = 100001;
int main()
{
int n,best[MAX],a[MAX], max,poz[MAX],p;
scanf("%d",&n);
for(int i=1;i<=n;++i)scanf("%d",&a[i]);
best[n]=1;
poz[n]=-1;
max=1;
p=n;
for(int i=n-1;i>=1;--i)
{
best[i]=1;
poz[i]=-1;
for(int j=i+1;j<=n;++j)
if(a[i]<a[j] && best[i]<best[j]+1)
{
best[i]=best[j]+1;
poz[i]=j;
if(best[i]>max){
max=best[i];
p=i;
}
}
}
printf("%d\n",max);
while(p!=-1)
{
printf("%d ",a[p]);
p=poz[p];
}
return 0;
}