Pagini recente » Cod sursa (job #1344735) | Cod sursa (job #105978) | Cod sursa (job #946511) | Cod sursa (job #138442) | Cod sursa (job #1473649)
#include <stdio.h>
#include <stdlib.h>
int get_index_best(int v[], int best[], int i){
int max=0, poz=-1, j;
for (j=0;j<i;j++){
if ( (v[j]<v[i]) && (best[j]>max) )
{
max = best[j];
poz = j ;
}
}
return poz;
}
int main()
{
FILE *f,*g;
int v[100000], best[100000], pre[100000];
int imax=0, n,i;
f = fopen("scmax.in","r");
g = fopen("scmax.out","w");
fscanf(f,"%d",&n);
for(i=0; i<n; i++){
fscanf(f,"%d",&v[i]);
int interm = get_index_best(v,best,i);
if (interm == -1){
best[i] = 1;
pre[i] = -1;
}else{
best[i] = best[interm] + 1;
pre[i] = interm;
if (best[i]>best[imax])
imax = i;
}
}
fprintf(g,"%d",best[imax]);
fclose(f);
fclose(g);
return 0;
}