Pagini recente » Cod sursa (job #2593652) | Cod sursa (job #3150144) | Cod sursa (job #2130244) | Cod sursa (job #506671) | Cod sursa (job #897881)
Cod sursa(job #897881)
#include <fstream>
#include <list>
using namespace std;
int main()
{
ifstream in("scmax.in");
ofstream out("scmax.out");
int n, lmax, imax;
in>>n;
int v[n], m[n], p[n];
lmax = 1, imax = 0;
for (int i = 0; i < n; i++) {
in>>v[i];
m[i] = 1;
p[i] = -1;
for (int j = 0; j < i; j++) {
if (v[j] < v[i])
if (m[j] + 1 > m[i]) {
m[i] = m[j] + 1
p[i] = j;
}
}
if (m[i] > lmax) {
lmax = m[i];
imax = i;
}
}
out<<lmax<<endl;
list<int> lst;
while (imax != -1) {
lst.push_front(v[imax]);
imax = p[imax];
}
while (!lst.empty()) {
out<<lst.front()<<" ";
lst.pop_front();
}
return 0;
}