Mai intai trebuie sa te autentifici.
Cod sursa(job #422966)
Utilizator | Data | 23 martie 2010 13:02:15 | |
---|---|---|---|
Problema | Subsir crescator maximal | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.69 kb |
#include <stdio.h>
#define DIM 100001
FILE *f1 = fopen("scmax.in","r");
FILE *f2 = fopen("scmax.out","w");
int a[DIM];
int t[DIM];
int opt[DIM];
int n;
int i,j,x;
int max;
void func(int x){
if(x > 0){
func(t[x]);
fprintf(f2,"%d ",a[x]);
}
}
int main(){
fscanf(f1,"%d\n",&n);
for(i=1; i<=n; i++){
fscanf(f1,"%d ",&a[i]);
max = 0;
for(j=1; j<i; j++)
if(a[i] > a[j])
if(max < opt[j]){
max = opt[j];
t[i] = j;
x = i;
}
opt[i] = max + 1;
}
fprintf(f2,"%d\n",opt[x]);
// x = n;
// while(x){
// fprintf(f2,"%d ",a[x]);
// x = t[x];
// }
func(x);
fclose(f1);
fclose(f2);
return 0;
}