Pagini recente » Cod sursa (job #2951578) | Cod sursa (job #2599290) | Cod sursa (job #2611982) | Cod sursa (job #1046212) | Cod sursa (job #878211)
Cod sursa(job #878211)
#include<fstream>
#define nmax 100005
using namespace std;
int best[nmax],poz[nmax],lmax,p,n,v[nmax],i,j;
int main(){
ifstream in("scmax.in"); ofstream out("scmax.out");
in>>n;
for(i=1;i<=n;++i) in>>v[i];
best[n]=1; poz[n]=-1; lmax=1; p=n;
for(i=n-1;i>=1;--i){
best[i]=1; poz[i]=-1;
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]>lmax) lmax=best[i], p=i;
}
}
}
out<<lmax<<'\n'; i=p;
while(i!=-1){
out<<v[i]<<' ';
i=poz[i];
}
out<<'\n';
out.close(); return 0;
}