Pagini recente » Cod sursa (job #1470155) | Cod sursa (job #2102179) | Cod sursa (job #1615236) | Cod sursa (job #1232888) | Cod sursa (job #2138373)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
int n, v[100002], dp[100002], poz[100002], maxI = 1, maxx;
vector<int> afis;
int main()
{
fin >> n;
for( int i = 1 ; i <= n ; ++i ){
fin >> v[i];
}
dp[1] = 1;
poz[1] = 0;
for( int i = 2 ; i <= n ; ++i ){
for( int j = 1 ; j < i ; ++j ){
if( v[j] < v[i] && dp[j] > dp[i] ){
dp[i] = dp[j];
poz[i] = j;
}
}
++dp[i];
if( dp[i] > maxx ){
maxx = dp[i];
maxI = i;
}
}
fout << maxx << "\n";
for( int i = maxI ; i ; i = poz[i] ){
afis.push_back(v[i]);
}
for( int i = afis.size() - 1 ; i >= 0 ; --i ){
fout << afis[i] << " ";
}
return 0;
}