Pagini recente » Clasament preoni_nicu4 | Cod sursa (job #364604) | Cod sursa (job #1759593) | Cod sursa (job #364601) | Cod sursa (job #2119139)
#include <iostream>
#include <fstream>
using namespace std;
const int N=100001;
int a[N], n, dp[N], pred[N], lmax, pmax;
ifstream f ("scmax.in");
ofstream g ("scmax.out");
void subsir (int p)
{
if (pred[p])
{
subsir(pred[p]);
}
g<<a[p]<<" ";
}
int main()
{
int i, j;
f>>n;
for (i=1; i<=n; i++)
{
f>>a[i];
}
pmax=0;
for (i=1; i<=n; i++)
{
lmax=0;
for (j=1; j<i; j++)
{
if (a[j]<a[i])
{
if (dp[j]>lmax)
{
lmax=dp[j];
pred[i]=j;
}
}
}
dp[i]=1+lmax;
if (dp[i]>dp[pmax])
{
pmax=i;
}
}
g<<dp[pmax]<<'\n';
subsir(pmax);
return 0;
}