Pagini recente » Cod sursa (job #1055540) | Cod sursa (job #159976) | Cod sursa (job #116443) | Cod sursa (job #2648944) | Cod sursa (job #3201633)
#include<bits/stdc++.h>
using namespace std;
ifstream fin ("scmax.in");
ofstream fout ("scmax.out");
const int nmax=1e6+3;
int best[nmax], a[nmax], poz[nmax], mx, sol=0, p, n;
void dp() {
int i,j;
best[n]=1;
poz[n]=-1;
mx=1;
p=n;
for(i=n-1;i>=1;--i){
best[i]=1;
poz[i]=-1;
for(j=i+1;j<=n;++j)
if(a[i]<a[j] && best[i]<=best[j]){
best[i]=best[j]+1;
poz[i]=j;
if(best[i]>mx) mx=best[i],p=i;
}
}
fout << mx << "\n";
}
void constr(){
int i;
i=p;
while(i!=-1){
fout << a[i] << " ";
i=poz[i];
}
}
int main(){
fin >> n;
for (int i=1;i<=n;++i) fin >> a[i];
dp();
constr();
return 0;
}