Pagini recente » Cod sursa (job #2392527) | Cod sursa (job #1781195) | Cod sursa (job #650904) | Cod sursa (job #2356298) | Cod sursa (job #729219)
Cod sursa(job #729219)
//Include
#include <fstream>
using namespace std;
//Constante
const int MAX_SIZE = (int)1e5+1;
//Functii
void drum(int x);
//Variabile
ifstream in("scmax.in"); // Si tu ai nume naspa
ofstream out("scmax.out");
int n;
int maxFound, maxFoundPoz;
int best[MAX_SIZE], tata[MAX_SIZE], oldVector[MAX_SIZE];
//Main
int main()
{
in >> n >> oldVector[1];
best[1] = 1;
for(int i=2 ; i<=n ; ++i)
{
in >> oldVector[i];
maxFound = maxFoundPoz = 0;
for(int j=1 ; j<i ; ++j)
if(oldVector[j] < oldVector[i])
{
if(best[j] > maxFound)
{
maxFoundPoz = j;
maxFound = best[j];
}
}
best[i] = max(best[i-1], maxFound + 1);
tata[i] = maxFoundPoz;
}
out << best[n] << '\n';
drum(n);
out << '\n';
in.close();
out.close();
return 0;
}
void drum(int x)
{
if(tata[x])
drum(tata[x]);
out << oldVector[x] << ' ';
}