Pagini recente » Cod sursa (job #1437162) | Cod sursa (job #1679803) | Cod sursa (job #3225166) | Cod sursa (job #157307) | Cod sursa (job #3222657)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("scmax.in");
ofstream fout ("scmax.out");
int dp[100005];
int v [100005];
int pre[100005];
int n;
void debug (int arr[])
{
for (int i=1; i<=n; i++) {
cout<<arr[i]<<' ';
}
cout<<endl;
}
/*
Subproblema: cel mai lung subsir
crescator maximal care incepe cu pozitia i.
*/
int main()
{
cin.tie(0); cin.sync_with_stdio(false);
cout.tie(0); cout.sync_with_stdio(false);
int elem;
fin>>n;
for (int i=1; i<=n; i++) fin>>v[i];
for (int i=2; i<=n; i++) {
for (int j=1; j<i; j++) {
if (v[j]<v[i]) {
if (dp[i]<dp[j]) {
dp[i]=dp[j];
pre[i]=j;
}
}
}
dp[i]++;
}
int bst=0;
for (int i=1; i<=n; i++) {
if (dp[i]>dp[bst]) bst=i;
}
fout<<dp[bst]<<'\n';
stack <int> st;
while (bst!=0) {
st.push(v[bst]);
bst=pre[bst];
}
while (!st.empty()) {
fout<<st.top()<<' ';
st.pop();
}
return 0;
}