Pagini recente » Cod sursa (job #2434228) | Cod sursa (job #1632021) | Cod sursa (job #283871) | Cod sursa (job #3264071) | Cod sursa (job #1745100)
#include <iostream>
#include <fstream>
#define NMAX 100010
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
unsigned long long v[NMAX];
unsigned long long pre[NMAX];
unsigned long long cost[NMAX];
unsigned int n;
void apeleazaRec(int poz,int len){
if(poz!=-1){
apeleazaRec(pre[poz],len+1);
g << v[poz] << ' ';
}
else g << len << '\n';
}
void rezolva(){
f >> n;
for(unsigned int i=0;i<n;i++) { f >> v[i]; cost[i]=1; pre[i]=-1;}
for(int i=1;i<n;i++)
for(int j=0;j<i;j++)
if(v[i] > v[j] && cost[i] < cost[j]+1){
cost[i] = cost[j]+1;
pre[i] = j;
}
int maxim = cost[0];
int poz=0;
for(int i=1;i<n;i++)
if(maxim < cost[i]){
maxim = cost[i];
poz=i;
}
apeleazaRec(poz,0);
}
int main()
{
rezolva();
return 0;
}