Pagini recente » Cod sursa (job #2303326) | Cod sursa (job #1961117) | Cod sursa (job #656555) | Cod sursa (job #2934863) | Cod sursa (job #2443004)
#include <fstream>
#define MAX 100003
using namespace std;
ifstream in("scmax.in");
ofstream out("scmax.out");
int N, v[MAX], best[MAX], poz[MAX], p, maxx;
void read()
{
in >> N;
for(int i = 1; i<=N; i++)
in >> v[i];
}
void dinamic()
{
int i,j;
best[N]=1;
poz[N]=-1;
maxx=1; p=N;
for(int i = N - 1; i >= 1; i--)
{
best[i] = 1;
poz[i] = -1;
for(int j = i + 1; j<=N; j++)
{
if(v[i] < v[j] && best[i] < best[j] + 1)
{
best[i] = best[j] + 1;
poz[i] = j;
if(best[i] > maxx) maxx = best[i], p = i;
}
}
}
}
void constr()
{
int i = p;
while(i != -1)
{
out << v[i] <<' ';
i = poz[i];
}
}
int main()
{
read();
dinamic();
out << maxx <<"\n";
constr();
}