Pagini recente » Cod sursa (job #250080) | Cod sursa (job #2086648) | Cod sursa (job #707853) | Cod sursa (job #1497335) | Cod sursa (job #1090334)
// Include
#include <fstream>
#include <algorithm>
using namespace std;
// Constante
const int sz = (int)1e5+1;
// Functii
void route(int node);
// Variabile
ifstream in("scmax.in");
ofstream out("scmax.out");
int num;
int values[sz], best[sz], father[sz];
// Main
int main()
{
in >> num;
for(int i=1 ; i<=num ; ++i)
in >> values[i];
for(int i=1 ; i<=num ; ++i)
{
best[i] = 1;
for(int j=1 ; j<i ; ++j)
{
if(values[j] < values[i])
{
if(best[i] < best[j] + 1)
{
best[i] = best[j] + 1;
father[i] = j;
}
}
}
}
int pos = max_element(best+1, best+num+1) - best;
out << best[pos] << '\n';
route(pos);
out << '\n';
in.close();
out.close();
return 0;
}
void route(int node)
{
if(father[node])
route(father[node]);
out << values[node] << ' ';
}