Pagini recente » Cod sursa (job #325767) | Cod sursa (job #2420077) | Cod sursa (job #1139404) | Cod sursa (job #2931528) | Cod sursa (job #1841013)
#include <fstream>
#include <vector>
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
vector<int> v, l, poz;
void scmax()
{
int n = v.size();
l[n - 1] = 1;
poz[n - 1] = -1;
for (int i = n - 2; i >= 0; --i)
{
l[i] = 0;
poz[i] = -1;
for (int j = i + 1; j < n; ++j)
if (v[i] < v[j] && l[j] >= l[i] + 1)
{
l[i] = l[j] + 1;
poz[i] = j;
}
if (!l[i])
l[i] = 1;
}
}
int main()
{
int n;
f >> n;
l.resize(n);
poz.resize(n);
for (int i = 0; i < n; ++i)
{
int x;
f >> x;
v.push_back(x);
}
scmax();
int lg = 0, poz_max = -1;
for (int i = 0; i < n; ++i)
if (l[i] > lg)
{
poz_max = i;
lg = l[i];
}
g << lg << "\n";
while(poz_max != -1)
{
g << v[poz_max] << " ";
poz_max = poz[poz_max];
}
return 0;
}