forked from jessicatcr-zz/Legado-da-Copa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
programacaoDinamica.c
33 lines (29 loc) · 1.14 KB
/
programacaoDinamica.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*******************************************************************************
* programacaoDinamica.c *
* Propósito: *
* *
* @author Jéssica Taís C. Rodrigues *
* @version 1.0 08/07/2017 *
******************************************************************************/
#include <stdlib.h>
#include "bandeirola.h"
#include "programacaoDinamica.h"
int resolveProgDinamica(bandeirola *band, int N){
int *vetOPT, i, j, max, resultado = 1;
vetOPT = malloc(sizeof(int)*N);
ordenaBandeirolasPar(band, N);
for(i = 0; i < N; i++){
max = 1;
for(j = 0; j < i; j++){
if (band[j].impar < band[i].impar && (vetOPT[j]+1) > max){
max = vetOPT[j]+1;
}
}
vetOPT[i] = max;
if(resultado < max){
resultado = max;
}
}
free(vetOPT);
return resultado;
}