Pagini recente » Cod sursa (job #2499515) | Cod sursa (job #2796422) | Cod sursa (job #3180302) | Cod sursa (job #1786065) | Cod sursa (job #1605517)
#include <iostream>
#include <fstream>
#include <vector>
#include <utility>
using namespace std;
ifstream fin ("scmax.in");
ofstream fout ("scmax.out");
#define MAXN 100050
vector <int> x, best, previous;
int N;
int main()
{
fin >> N;
x.resize(N+1);
best.resize(N+1);
previous.resize(N+1);
best[N] = 1;
previous[N] = -1;
int _max = 0;
int position = N;
for (int i = N; i >= 1; --i)
{
best[i] = 1;
previous[i] = -1;
for (int j = i+1; j <= N; ++j)
if (x[i] < x[j] && best[i] < best[j] + 1)
{
best[i] = best[j] + 1;
previous[i] = j;
if (best[i] > _max)
{
_max = best[i];
position = i;
}
}
}
fout <<_max <<'\n';
int i = position;
while (i != -1)
{
fout <<x[i] <<' ';
i = previous[i];
}
fout <<'\n';
return 0;
}