Pagini recente » Cod sursa (job #881532) | Cod sursa (job #658902) | Cod sursa (job #964173) | Cod sursa (job #458609) | Cod sursa (job #1502408)
#include <bits/stdc++.h>
using namespace std;
int best[100001],poz[100001],v[100001];
ifstream f("scmax.in");
ofstream g("scmax.out");
int main()
{
int n,j,i,max=0,p;
f>>n;
for(i=1;i<=n;i++)
f>>v[i];
best[n]=1;
poz[n]=-1;
for(i=n-1;i>=1;i--)
{
best[i]=1;
poz[i]=-1;
for(j=i+1;j<=n;j++)
if(v[i]<v[j]&&best[i]<best[j]+1)
{
best[i]=best[j]+1;
poz[i]=j;
}
if(best[i]>max)
{
max=best[i];
p=i;
}
}
g<<max<<"\n";
while(p!=-1)
{
g<<v[p]<<" ";
p=poz[p];
}
return 0;
}