Pagini recente » Cod sursa (job #1981039) | Cod sursa (job #1958287) | Cod sursa (job #380581) | Cod sursa (job #54855) | Cod sursa (job #3264114)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("scmax.in");
ofstream fout("scmax.out");
int n, p, maxx;
const int Max = 1e5 + 1;
vector<int> a(Max), dp(Max, 1), parent(Max);
stack<int> s;
int main()
{
ios::sync_with_stdio(false);
fin.tie(NULL);
fin >> n;
for(int i = 1; i <= n; ++i)
fin >> a[i];
for(int i = 1; i <= n; ++i)
{
for(int j = 1; j < i; ++j)
if(a[j] < a[i] && dp[i] < dp[j] + 1)
{
dp[i] = dp[j] + 1;
parent[i] = j;
}
if(dp[i] > maxx)
{
maxx = dp[i];
p = i;
}
}
for(int i = p; i; i = parent[i])
s.push(i);
fout << maxx << "\n";
while(!s.empty())
{
fout << a[s.top()] << " ";
s.pop();
}
fin.close();
fout.close();
return 0;
}