Pagini recente » Cod sursa (job #2091546) | Cod sursa (job #1917241) | Cod sursa (job #388026) | Cod sursa (job #411891) | Cod sursa (job #2963599)
#include <fstream>
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
const int N = 1024;
int lung[N+1], x[N+1], n;
void refac_subsir(int p, int l, int val){
if(l == 0)
return;
if(lung[p] == l && x[p] < val){
refac_subsir(p-1,l-1,x[p]);
fout<<x[p]<<' ';
}else{
refac_subsir(p-1,l,val);
}
}
int main()
{
fin>>n;
int pmax = 1;
for(int i = 1; i <= n; i++){
int l_j = 0;
fin>>x[i];
for(int j = 1; j < i; j++){
if(x[j] < x[i]){
if(lung[j] > l_j)
l_j = lung[j];
}
}
lung[i] = 1 + l_j;
if(lung[i] > lung[pmax]) pmax = i;
}
fout<<lung[pmax]<<'\n';
refac_subsir(pmax,lung[pmax], x[pmax]+1);
return 0;
}