Pagini recente » Cod sursa (job #489583) | Cod sursa (job #2271655) | Cod sursa (job #1238681) | Cod sursa (job #1352125) | Cod sursa (job #2770767)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
vector<int> out;
int lis(int arr[], int n)
{
int lis[n];
lis[0] = 1;
for (int i = 1; i < n; i++) {
lis[i] = 1;
for (int j = 0; j < i; j++)
if (arr[i] > arr[j] && lis[i] < lis[j] + 1){
lis[i] = lis[j] + 1;}
out.push_back(lis[i-1]);
}
out.push_back(lis[n-1]);
return *max_element(lis, lis + n);
}
int main()
{
int n;
fin >> n;
int arr[n];
for(int i = 0; i < n; i++)
{
fin >> arr[i];
}
int ccout = lis(arr, n);
fout << ccout << '\n';
vector<int> ord;
vector<long int> coout;
int current = 1, pos = 1;
ord.push_back(0);
while(pos < n)
{
if(arr[pos] > arr[pos-1])
{
ord.push_back(pos);
}
else{ord.push_back(0);}
pos++;
}
coout.clear();
pos = 0;
while(ccout != out[pos]){
++pos;}
coout.push_back(arr[pos]);
int i = ord.size()-1;
while(ord[i] != 0)
{
coout.push_back(arr[ord[i]]);
--i;
}
for(int i = ccout; i > -1; i--)
{
fout << coout[i] << ' ';
}
return 0;
}