Pagini recente » Cod sursa (job #213604) | Cod sursa (job #17227) | Cod sursa (job #833257) | Cod sursa (job #1504216) | Cod sursa (job #536028)
Cod sursa(job #536028)
#include <stdio.h>
#define MAX 100002
int a[MAX],best[MAX],honnan[MAX],max=0,utolso,n;
int main(){
freopen("scmax.in","r",stdin);
freopen("scmax.out","w",stdout);
scanf("%d",&n);
int i,j,maxx,temp;
for(i=1;i<=n;i++){
scanf("%d",&a[i]);
}
for(i=1;i<=n;i++){
maxx=0;
for(j=1;j<=i-1;j++){
if((best[j]>maxx)&&(a[j]<a[i])){
maxx=best[j];
honnan[i]=j;
}
}
best[i]=maxx+1;
if(best[i]>max){max=best[i];utolso=i;}
}
temp=utolso;
for(i=1;i<=max;i++){
best[i]=a[temp];
temp=honnan[temp];
}
printf("%d\n",max);
for(i=max;i>=1;i--){
printf("%d ",best[i]);
}
return 0;}