Pagini recente » Cod sursa (job #2659154) | Cod sursa (job #864480) | Cod sursa (job #1861711) | Cod sursa (job #1090606) | Cod sursa (job #2706137)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
void scmax(vector<unsigned> a, unsigned n)
{
vector<unsigned> scmax(n, 1);
unsigned lmax = 1;
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
for(int i = n - 2; i >= 0; --i)
for(unsigned j = i + 1; j < n; ++j)
if(a[i] < a[j])
{
scmax[i] = MAX(scmax[i], scmax[j] + 1);
lmax = MAX(lmax, scmax[i]);
}
#undef MAX
ofstream out("scmax.out");
out << lmax << endl;
for(unsigned i = 0; i < n; ++i)
if(scmax[i] == lmax)
{
out << a[i] << ' ';
--lmax;
if(!lmax)
break;
}
out.close();
}
int main()
{
unsigned n;
ifstream in("scmax.in");
in >> n;
vector<unsigned> a(n);
for(unsigned i = 0; i < n;)
in >> a[i++];
in.close();
scmax(a, n);
return 0;
}