Pagini recente » Cod sursa (job #1932192) | Cod sursa (job #2298580) | Cod sursa (job #1853936) | Cod sursa (job #643882) | Cod sursa (job #661240)
Cod sursa(job #661240)
#include <fstream>
using namespace std;
int s[100001],a[100001],poz[100001],i,j,pozmax,n,maxim;
int main ()
{
ifstream f ("scmax.in");
ofstream g ("scmax.out");
f >> n;
for (i=1; i<=n; i++)
f>>s[i];
a[n]=1;
poz[n]=-1;
maxim=1;
pozmax=n;
for(i=n-1; i>0; i--)
{
a[i]=1;
poz[i]=-1;
for (j=i+1; j<=n; j++)
if (s[i]<s[j] && a[i]<a[j]+1)
{
a[i]=a[j]+1;
poz[i]=j;
if (a[i]>maxim)
{
maxim=a[i];
pozmax=i;
}
}
}
g << maxim << endl;
while (pozmax!=-1)
{
g<<s[pozmax]<<' ';
pozmax=poz[pozmax];
}
return 0;
}