Pagini recente » Cod sursa (job #2402646) | Cod sursa (job #411937) | Cod sursa (job #1237366) | Cod sursa (job #1391302) | Cod sursa (job #1470764)
#include <stdio.h>
#include <stdlib.h>
#define MAXN 100005
int n,i,j,maxt,aux, maxti = 1, a[MAXN], best[MAXN], pre[MAXN], sol[MAXN];
int main()
{
FILE *in = fopen("scmax.in", "r");
FILE *out = fopen("scmax.out", "w");
fscanf(in,"%d",&n);
for(i = 1; i <= n; i++)
fscanf(in, "%d", a+i);
for(i = 1; i <= n; i++)
{
for(j = 1; j < i; j++)
if(a[j] < a[i] && best[j] + 1 > best[i]) best[i] = best[j] + 1, pre[i] = j;
if(best[i] > maxt ) maxt = best[i], maxti = i;
}
fprintf(out, "%d\n", best[maxti] + 1);
i = 0;
aux = maxti;
while(maxti) sol[i++] = a[maxti], maxti = pre[maxti];
for(i = best[aux] ; i >= 0; i--)
fprintf(out,"%d ", sol[i]);
return 0;
}