Cod sursa(job #1857685)

Utilizator PetrescuAlexandru Petrescu Petrescu Data 26 ianuarie 2017 15:38:23
Problema Subsir crescator maximal Scor 20
Compilator cpp Status done
Runda Arhiva educationala Marime 0.63 kb
#include <stdio.h>
#include <iostream>
#define MAX 1000

using namespace std;
int v[MAX], lmax[MAX];
int main()
{
  FILE *fin, *fout;
  int n, i, max, j;

  fin = fopen("scmax.in", "r");
  fout = fopen("scmax.out", "w");
  fscanf(fin, "%d", &n);
  for(i = 0; i < n; i++)fscanf(fin, "%d", &v[i]);
  lmax[0] = 1;
  for(i = 1; i < n; i++)
  {
    max = 0;
    for(j = i - 1; j >= 0; j--)
      if(v[j] <= v[i] && max < lmax[j])max = lmax[j];
    lmax[i] = max + 1;
  }
  max = 0;
  for(i = 0; i < n; i++)if(max < lmax[i])max = lmax[i];
  fprintf(fout, "%d", max);
  fclose( fin );
  fclose( fout );
  return 0;
}