Fichas
Maximum sum such that no two elements are adjacent
Fichas del conjunto (1)
- 1Given an array of positive numbers, find the maximum sum of a subsequence with the constraint that no 2 numbers in the sequence should be adjacent in the array. Input : arr[] = {1, 2, 3} Output : 4int FindMaxAdjacentSum(int a[],int n){
int excl = 0;
int incl = a[0];
for(int i = 1; i< a.length; i++){
int excl_new = (incl>excl)?incl:excl;
incl = excl + arr[i];
excl = excl_new;
}
}
Información
- Descripción
- Fichas sobre Maximum sum such that no two elements are adjacent, creado por Suhas S el 31/03/2018.
- Creado por
- Suhas S
- Visitas
- 0
- Valoración