text: Maximum sum possible from given Matrix by performing given operations | Function to print the maximum sum possible by selecting at most one element from each column such that no consecutive pairs are selected from a single row ; Initialize variables ; Traverse each column ; Prvar answer ; Driver Code ; Numberof columns
code: function maxSum ( arr , n ) { var r1 = 0 , r2 = 0 ; for ( i = 0 ; i < n ; i ++ ) { var temp = r1 ; r1 = Math . max ( r1 , r2 + arr [ 0 ] [ i ] ) ; r2 = Math . max ( r2 , temp + arr [ 1 ] [ i ] ) ; } document . write ( Math . max ( r1 , r2 ) ) ; } var arr = [ [ 1 , 50 , 21 , 5 ] , [ 2 , 10 , 10 , 5 ] ] ; var n = arr [ 0 ] . length ; maxSum ( arr , n ) ;