Pagini recente » Cod sursa (job #1053609) | Cod sursa (job #2057547) | Cod sursa (job #1244180) | Cod sursa (job #538951) | Cod sursa (job #899221)
Cod sursa(job #899221)
#include<stdio.h>
#include<algorithm>
using namespace std;
FILE *in,*out;
int n,i,best[100001],v[100001],tata[100001],j,maxfoundpos,maxfound,wtf[10001];
int main()
{
in=fopen("scmax.in","rt");
out=fopen("scmax.out","wt");
fscanf(in,"%d",&n);
for(i=1;i<=n;i++)
fscanf(in,"%d",&v[i]);
best[1]=1;
for(i=2;i<=n;i++)
{
maxfoundpos=0;
maxfound=0;
for(j=1;j<i;j++)
{
if(v[j]<v[i])
{
if(best[j]>maxfound)
{
maxfound=best[j];
maxfoundpos=j;
}
}
best[i]=maxfound+1;
tata[i]=maxfoundpos;
}
}
int poz=max_element(best+1,best+n+1)-best;
fprintf(out,"%d\n",best[poz]);
int curent =poz;
int u=0;
while(curent)
{
wtf[++u]=v[curent];
curent=tata[curent];
}
for(i=u;i>=1;--i)
fprintf(out,"%d ",wtf[i]);
fclose(in);
fclose(out);
return 0;
}