Pagini recente » Cod sursa (job #1262255) | Cod sursa (job #48356) | Cod sursa (job #3236585) | Cod sursa (job #3256285) | Cod sursa (job #1049853)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
void show (vector<int> &v) {
for (int i = 0, len = v.size(); i < len; i++) {
cout << v[i] << ' ';
}
cout << '\n';
}
int main (int argc, char const *argv[])
{
ifstream in("scmax.in");
int N = 0;
in >> N;
vector<int> v(N);
for (int i = 0; i < N; i++) {
in >> v[i];
}
in.close();
int max = -0x7fffffff, maxIndex = 0;
vector<int> len(N, 1), poz(N, -1);
for (int i = N - 2; i >= 0; i--) {
for (int j = i + 1; j < N; j++) {
if (v[i] < v[j] && len[i] <= len[j]) {
len[i] = len[j] + 1;
poz[i] = j;
if (max < len[i]) {
max = len[i];
maxIndex = i;
}
}
}
}
// show(v);
// show(len);
// show(poz);
ofstream out("scmax.out");
out << max << endl;
for (int i = maxIndex; i != -1; i = poz[i]) {
out << v[i] << ' ';
}
out << endl;
return 0;
}