Pagini recente » Cod sursa (job #2587197) | Cod sursa (job #2878526) | Cod sursa (job #2252831) | Cod sursa (job #2266610) | Cod sursa (job #2680432)
#include <bits/stdc++.h>
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
int dp[100005];
int pre[100005];
int v[100005];
int n;
int sirmax;
int pozmax;
stack < int > st;
int ctr;
int main()
{
f >> n;
for (int i=1;i<=n;i++) {
f >> v[i];
}
dp[1]=1;
for (int i=2;i<=n;i++) {
for (int j=1;j<i;j++) {
if (v[i]>v[j] && dp[j]+1>dp[i]) {
dp[i]=dp[j]+1;
pre[i]=j;
if (dp[i]>sirmax) {
sirmax = dp[i];
pozmax = i;
}
}
}
if (dp[i]==0) {
dp[i]=1;
}
}
while (pozmax!=0) {
st.push(v[pozmax]);
ctr++;
pozmax = pre[pozmax];
}
g << ctr << '\n';
while (st.empty()==0) {
g << st.top()<<" ";
st.pop();
}
return 0;
}