Cod sursa(job #915483)
| Utilizator | Data | 15 martie 2013 02:51:11 | |
|---|---|---|---|
| Problema | Subsir crescator maximal | Scor | 70 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.61 kb |
#include <stdio.h>
using namespace std;
FILE *f=fopen("scmax.in","r");
FILE *g=fopen("scmax.out","w");
int i,j,N,A[100000],st[100000],P[100000];
int main()
{
fscanf(f,"%d",&N);
for(i=1;i<=N;i++)
fscanf(f,"%d",&A[i]);
int L(1),p(1);
for(i=2;i<=N;i++)
{
for(j=1;j<i;j++)
if((A[j]<A[i])&&(st[j]+1>st[i]))
{st[i]=st[j]+1; P[i]=j;}
if(st[i]>=L) {L=st[i]+1; p=i;}
}
for(i=L;i>=1;i--)
{
st[i]=A[p];
p=P[p];
}
fprintf(g,"%d\n",L);
for(i=1;i<=L;i++)
fprintf(g,"%d ",st[i]);
return 0;
}
