Flashcards
Maximum sum such that no two elements are adjacent
Flashcards do 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;
}
}
Informações
- Descrição
- FlashCards sobre Maximum sum such that no two elements are adjacent, criado por Suhas S em 31-03-2018.
- Criado por
- Suhas S
- Visualizações
- 0
- Avaliação