dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
let MAX = 100 ; function recur ( ind , cnt , last , a , n , k , dp ) { if ( cnt == k ) return 0 ; if ( ind == n ) return - 1e9 ; if ( dp [ ind ] [ cnt ] != - 1 ) return dp [ ind ] [ cnt ] ; let ans = 0 ; for ( let i = ind ; i < n ; i ++ ) { if ( cnt % 2 == 0 ) ans = Math . max ( ans , recur ( i + 1 , cnt + 1 , i , a , n , k , dp ) ) ; else ans = Math . max ( ans , __gcd ( a [ last ] , a [ i ] ) + recur ( i + 1 , cnt + 1 , 0 , a , n , k , dp ) ) ; } return dp [ ind ] [ cnt ] = ans ; } function __gcd ( a , b ) { if ( b == 0 ) return a ; return __gcd ( b , a % b ) ; } let a = [ 4 , 5 , 3 , 7 , 8 , 10 , 9 , 8 ] ; let n = a . length ; let k = 4 ; let dp = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { dp [ i ] = new Array ( MAX ) ; for ( let j = 0 ; j < MAX ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } document . write ( recur ( 0 , 0 , 0 , a , n , k , dp ) ) ;

Index/key variables: cnt, i, ind, j, last
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function find ( s ) { if ( s . length == 0 ) return 0 ; var c = 1 ; var d = " " ; for ( var i = 0 ; i < s . length ; i ++ ) { d += s [ i ] ; var s2 = s . substring ( i + 1 , i + 1 + d . length ) ; if ( s2 == d ) { c = 1 + find ( s . substring ( i + 1 ) ) ; break ; } } return c ; } var s = " " ; document . write ( find ( s ) ) ;

Index/key variables: i
Accumulator variables: d, i
Iterator variables: i
Javascript program:
var MAX = 10 ; function maximizeSum ( a , n , ind , k , dp ) { if ( k == 0 ) { if ( ind == n ) return 0 ; else return - 1000000000 ; } else if ( ind == n ) return - 1000000000 ; else if ( dp [ ind ] [ k ] != - 1 ) return dp [ ind ] [ k ] ; else { var ans = 0 ; var mini = a [ ind ] ; for ( i = ind ; i < n ; i ++ ) { mini = Math . min ( mini , a [ i ] ) ; ans = Math . max ( ans , maximizeSum ( a , n , i + 1 , k - 1 , dp ) + mini ) ; } return dp [ ind ] [ k ] = ans ; } } var a = [ 5 , 7 , 4 , 2 , 8 , 1 , 6 ] ; var k = 3 ; var n = a . length ; var dp = Array ( MAX ) . fill ( ) . map ( ( ) => Array ( MAX ) . fill ( 0 ) ) ; for ( var i = 0 ; i < MAX ; i ++ ) { for ( j = 0 ; j < MAX ; j ++ ) dp [ i ] [ j ] = - 1 ; } document . write ( maximizeSum ( a , n , 0 , k , dp ) ) ;

Index/key variables: i, ind, j, k
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let dp ; function solveUtil ( start , bucket , str , K ) { let N = str . length ; if ( start == N ) { if ( bucket == K ) { return 0 ; } return Number . MAX_VALUE ; } if ( bucket == K ) { return Number . MAX_VALUE ; } if ( dp [ start ] [ bucket ] != - 1 ) { return dp [ start ] [ bucket ] ; } let zeroes = 0 ; let ones = 0 ; let ans = Number . MAX_VALUE ; for ( let i = start ; i < N ; ++ i ) { if ( str [ i ] == ' ' ) { ones ++ ; } else { zeroes ++ ; } if ( ones * zeroes > ans ) { break ; } let temp = solveUtil ( i + 1 , bucket + 1 , str , K ) ; if ( temp != Number . MAX_VALUE ) { ans = Math . min ( ans , temp + ( ones * zeroes ) ) ; } } return dp [ start ] [ bucket ] = ans ; } function solve ( str , K ) { let N = str . length ; dp = new Array ( N ) ; for ( let i = 0 ; i < N ; i ++ ) { dp [ i ] = new Array ( K ) ; for ( let j = 0 ; j < K ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } let ans = solveUtil ( 0 , 0 , str , K ) ; return ans == Number . MAX_VALUE ? - 1 : ans ; } let S = " " ; let K = 2 ; document . write ( solve ( S , K ) ) ;

Index/key variables: bucket, i, j, start
Accumulator variables: i, j, ones, zeroes
Iterator variables: i, j
Javascript program:
function Probability ( p , n ) { var dp = Array ( n + 1 ) . fill ( 0 ) . map ( x => Array ( n + 1 ) . fill ( 0 ) ) ; dp [ 0 ] [ 0 ] = 1.0 ; for ( var i = 1 ; i <= n ; i += 1 ) { for ( var j = 0 ; j <= i ; j += 1 ) { if ( j == 0 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] * ( 1.0 - p [ i ] ) ; else dp [ i ] [ j ] = dp [ i - 1 ] [ j ] * ( 1.0 - p [ i ] ) + dp [ i - 1 ] [ j - 1 ] * p [ i ] ; } } var ans = 0.0 ; for ( var i = parseInt ( ( n + 1 ) / 2 ) ; i <= n ; i += 1 ) ans += dp [ n ] [ i ] ; return ans ; } var p = [ 0.0 , 0.3 , 0.4 , 0.7 ] ; var n = p . length - 1 ; document . write ( Probability ( p , n ) ) ;

Index/key variables: i, j, n
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
const mod = 1000000007 ; let dp = new Array ( 55 ) ; for ( let i = 0 ; i < 55 ; i ++ ) dp [ i ] = new Array ( 55 ) . fill ( - 1 ) ; function NoofWays ( face , throws , sum ) { if ( sum == 0 && throws == 0 ) return 1 ; if ( sum < 0 throws == 0 ) return 0 ; if ( dp [ throws ] [ sum ] != - 1 ) return dp [ throws ] [ sum ] ; let ans = 0 ; for ( let i = 1 ; i <= face ; i ++ ) { ans += NoofWays ( face , throws - 1 , sum - i ) ; } return dp [ throws ] [ sum ] = ans ; } let faces = 6 , throws = 3 , sum = 12 ; document . write ( NoofWays ( faces , throws , sum ) ) ;

Index/key variables: i, sum, throws
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function maxHappiness ( A , N , v ) { let str ; let val = Array . from ( { length : N } , ( _ , i ) => 0 ) ; let wt = Array . from ( { length : N } , ( _ , i ) => 0 ) ; let c = 0 ; for ( let i = 0 ; i < N ; i ++ ) { str = v [ i ] ; c = 0 ; for ( let j = 0 ; j < str . length ; j ++ ) { if ( str [ j ] == ' ' ) c += 4 ; else if ( str [ j ] == ' ' ) c += 3 ; else if ( str [ j ] == ' ' ) c += 2 ; else c ++ ; } c *= str . length ; val [ i ] = c ; wt [ i ] = str . length ; } let k = new Array ( N + 1 ) ; for ( var i = 0 ; i < k . length ; i ++ ) { k [ i ] = new Array ( 2 ) ; } for ( let i = 0 ; i <= N ; i ++ ) { for ( let w = 0 ; w <= A ; w ++ ) { if ( i == 0 w == 0 ) k [ i ] [ w ] = 0 ; else if ( wt [ i - 1 ] <= w ) { k [ i ] [ w ] = Math . max ( val [ i - 1 ] + k [ i - 1 ] [ w - wt [ i - 1 ] ] , k [ i - 1 ] [ w ] ) ; } else { k [ i ] [ w ] = k [ i - 1 ] [ w ] ; } } } return k [ N ] [ A ] ; } let A = 5 ; let v = [ " " , " " , " " , " " , " " ] ; let N = v . length ; document . write ( maxHappiness ( A , N , v ) ) ;

Index/key variables: A, N, i, j, w
Accumulator variables: c, i, j, w
Iterator variables: i, j, w
Javascript program:
var C_MAX = 30 var max_arr_len = 10 var dp = Array . from ( Array ( max_arr_len ) , ( ) => Array ( C_MAX + 1 ) ) ; var v = Array . from ( Array ( max_arr_len ) , ( ) => Array ( C_MAX + 1 ) ) ; function findMax ( i , r , w , n ) { if ( r < 0 ) return - 1000000000 ; if ( i == n ) return 0 ; if ( v [ i ] [ r ] ) return dp [ i ] [ r ] ; v [ i ] [ r ] = 1 ; dp [ i ] [ r ] = Math . max ( w [ i ] + findMax ( i + 1 , r - w [ i ] , w , n ) , findMax ( i + 1 , r , w , n ) ) ; return dp [ i ] [ r ] ; } function preCompute ( w , n ) { for ( var i = C_MAX ; i >= 0 ; i -- ) findMax ( 0 , i , w , n ) ; } function ansQuery ( w ) { return dp [ 0 ] [ w ] ; } var w = [ 3 , 8 , 9 ] ; var n = w . length ; preCompute ( w , n ) ; var queries = [ 11 , 10 , 4 ] ; var q = queries . length ; for ( var i = 0 ; i < q ; i ++ ) document . write ( ansQuery ( queries [ i ] ) + " " ) ;

Index/key variables: i, r, w
Accumulator variables: i
Iterator variables: i
Javascript program:
var maxLen = 10 var dp = Array ( maxLen ) ; var v = Array ( maxLen ) ; var prefix_sum = Array ( maxLen ) ; ; function findPrefixSum ( arr , n ) { prefix_sum [ 0 ] = arr [ 0 ] ; for ( var i = 1 ; i < n ; i ++ ) prefix_sum [ i ] = arr [ i ] + prefix_sum [ i - 1 ] ; } function maxSum ( arr , i , n , k ) { if ( i + k > n ) return 0 ; if ( v [ i ] ) return dp [ i ] ; v [ i ] = 1 ; var x ; if ( i == 0 ) x = prefix_sum [ k - 1 ] ; else x = prefix_sum [ i + k - 1 ] - prefix_sum [ i - 1 ] ; dp [ i ] = Math . max ( maxSum ( arr , i + 1 , n , k ) , x + maxSum ( arr , i + k + 1 , n , k ) ) ; return dp [ i ] ; } var arr = [ 1 , 3 , 7 , 6 ] ; var n = arr . length ; var k = 1 ; findPrefixSum ( arr , n ) ; document . write ( maxSum ( arr , 0 , n , k ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
var max_size = 20 ; var max_k = 20 var dp = Array . from ( Array ( max_size ) , ( ) => Array ( max_k ) ) ; var v = Array . from ( Array ( max_size ) , ( ) => Array ( max_k ) ) ; var sum = 0 ; function findSum ( arr , n ) { for ( var i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; } function cntWays ( arr , i , ck , k , n , curr_sum ) { if ( sum % k != 0 ) return 0 ; if ( i != n && ck == k + 1 ) return 0 ; if ( i == n ) { if ( ck == k + 1 ) return 1 ; else return 0 ; } if ( v [ i ] [ ck ] ) return dp [ i ] [ ck ] ; curr_sum += arr [ i ] ; v [ i ] [ ck ] = 1 ; dp [ i ] [ ck ] = cntWays ( arr , i + 1 , ck , k , n , curr_sum ) ; if ( curr_sum == ( sum / k ) * ck ) dp [ i ] [ ck ] += cntWays ( arr , i + 1 , ck + 1 , k , n , curr_sum ) ; return dp [ i ] [ ck ] ; } var arr = [ 1 , - 1 , 1 , - 1 , 1 , - 1 ] ; var n = arr . length ; var k = 2 ; findSum ( arr , n ) ; document . write ( cntWays ( arr , 0 , 1 , k , n , 0 ) ) ;

Index/key variables: ck, i
Accumulator variables: curr_sum, i, sum
Iterator variables: i
Javascript program:
var arrSize = 51 ; var dp = Array ( arrSize ) ; var v = Array ( arrSize ) ; function sumMax ( i , arr , n ) { if ( i >= n - 1 ) return 0 ; if ( v [ i ] ) return dp [ i ] ; v [ i ] = true ; dp [ i ] = Math . max ( arr [ i ] + arr [ i + 1 ] + sumMax ( i + 3 , arr , n ) , sumMax ( i + 1 , arr , n ) ) ; return dp [ i ] ; } var arr = [ 1 , 1 , 1 , 1 ] ; var n = arr . length ; document . write ( sumMax ( 0 , arr , n ) ) ;

Index/key variables: i
Javascript program:
function MaxIncreasingSub ( arr , n , k ) { let dp = new Array ( n ) ; for ( let i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( 2 ) ; } let ans = - 1 ; for ( let i = 0 ; i < n ; i ++ ) for ( let j = 0 ; j < k + 1 ; j ++ ) dp [ i ] [ j ] = - 1 ; for ( let i = 0 ; i < n ; i ++ ) { dp [ i ] [ 1 ] = arr [ i ] ; } for ( let i = 1 ; i < n ; i ++ ) { for ( let j = 0 ; j < i ; j ++ ) { if ( arr [ j ] < arr [ i ] ) { for ( let l = 1 ; l <= k - 1 ; l ++ ) { if ( dp [ j ] [ l ] != - 1 ) { dp [ i ] [ l + 1 ] = Math . max ( dp [ i ] [ l + 1 ] , dp [ j ] [ l ] + arr [ i ] ) ; } } } } } for ( let i = 0 ; i < n ; i ++ ) { if ( ans < dp [ i ] [ k ] ) ans = dp [ i ] [ k ] ; } return ( ans == - 1 ) ? 0 : ans ; } let n = 8 , k = 3 ; let arr = [ 8 , 5 , 9 , 10 , 5 , 6 , 21 , 8 ] ; let ans = MaxIncreasingSub ( arr , n , k ) ; document . write ( ans ) ;

Index/key variables: i, j, k, l
Accumulator variables: i, j, l
Iterator variables: i, j, l
Javascript program:
var dp = Array . from ( { length : 200 } , ( _ , i ) => 0 ) ; var count = 0 ; function print ( idx ) { for ( var i = 1 ; i < idx ; i ++ ) { document . write ( dp [ i ] + " " ) ; } document . write ( ' ' ) ; } function solve ( remSum , maxVal , idx , count ) { if ( remSum == 0 ) { print ( idx ) ; count ++ ; return ; } for ( var i = maxVal ; i >= 1 ; i -- ) { if ( i > remSum ) { continue ; } else if ( i <= remSum ) { dp [ idx ] = i ; solve ( remSum - i , i , idx + 1 , count ) ; } } } var n = 4 , count = 0 ; solve ( n , n , 1 , count ) ;

Index/key variables: i, idx
Accumulator variables: count, i
Iterator variables: i
Javascript program:
const bitscount = 32 ; const n = 3 ; let prefix_count = new Array ( bitscount ) ; for ( let i = 0 ; i < bitscount ; i ++ ) { prefix_count [ i ] = new Array ( n ) ; for ( let j = 0 ; j < n ; j ++ ) prefix_count [ i ] [ j ] = new Array ( n ) ; } function findPrefixCount ( arr ) { for ( let i = 0 ; i < bitscount ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) { prefix_count [ i ] [ j ] [ 0 ] = ( ( arr [ j ] [ 0 ] >> i ) & 1 ) ; for ( let k = 1 ; k < n ; k ++ ) { prefix_count [ i ] [ j ] [ k ] = ( ( arr [ j ] [ k ] >> i ) & 1 ) ; prefix_count [ i ] [ j ] [ k ] += prefix_count [ i ] [ j ] [ k - 1 ] ; } } } for ( let i = 0 ; i < bitscount ; i ++ ) for ( let j = 1 ; j < n ; j ++ ) for ( let k = 0 ; k < n ; k ++ ) prefix_count [ i ] [ j ] [ k ] += prefix_count [ i ] [ j - 1 ] [ k ] ; } function rangeOr ( x1 , y1 , x2 , y2 ) { let ans = 0 ; for ( let i = 0 ; i < bitscount ; i ++ ) { let p ; if ( x1 == 0 && y1 == 0 ) p = prefix_count [ i ] [ x2 ] [ y2 ] ; else if ( x1 == 0 ) p = prefix_count [ i ] [ x2 ] [ y2 ] - prefix_count [ i ] [ x2 ] [ y1 - 1 ] ; else if ( y1 == 0 ) p = prefix_count [ i ] [ x2 ] [ y2 ] - prefix_count [ i ] [ x1 - 1 ] [ y2 ] ; else p = prefix_count [ i ] [ x2 ] [ y2 ] - prefix_count [ i ] [ x1 - 1 ] [ y2 ] - prefix_count [ i ] [ x2 ] [ y1 - 1 ] + prefix_count [ i ] [ x1 - 1 ] [ y1 - 1 ] ; if ( p != 0 ) ans = ( ans | ( 1 << i ) ) ; } return ans ; } let arr = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ] ; findPrefixCount ( arr ) ; let queries = [ [ 1 , 1 , 1 , 1 ] , [ 1 , 2 , 2 , 2 ] ] ; let q = queries . length ; for ( let i = 0 ; i < q ; i ++ ) document . write ( rangeOr ( queries [ i ] [ 0 ] , queries [ i ] [ 1 ] , queries [ i ] [ 2 ] , queries [ i ] [ 3 ] ) + " " ) ;

Index/key variables: i, j, k, x2, y2
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
let bitscount = 32 ; let n = 3 ; let prefix_count = new Array ( bitscount ) ; for ( let i = 0 ; i < bitscount ; i ++ ) { prefix_count [ i ] = new Array ( n ) ; for ( let j = 0 ; j < n ; j ++ ) { prefix_count [ i ] [ j ] = new Array ( n ) ; for ( let k = 0 ; k < n ; k ++ ) { prefix_count [ i ] [ j ] [ k ] = 0 ; } } } function findPrefixCount ( arr ) { for ( let i = 0 ; i < bitscount ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) { prefix_count [ i ] [ j ] [ 0 ] = ( ( arr [ j ] [ 0 ] >> i ) & 1 ) ; for ( let k = 1 ; k < n ; k ++ ) { prefix_count [ i ] [ j ] [ k ] = ( ( arr [ j ] [ k ] >> i ) & 1 ) ; prefix_count [ i ] [ j ] [ k ] += prefix_count [ i ] [ j ] [ k - 1 ] ; } } } for ( let i = 0 ; i < bitscount ; i ++ ) for ( let j = 1 ; j < n ; j ++ ) for ( let k = 0 ; k < n ; k ++ ) prefix_count [ i ] [ j ] [ k ] += prefix_count [ i ] [ j - 1 ] [ k ] ; } function rangeAnd ( x1 , y1 , x2 , y2 ) { let ans = 0 ; for ( let i = 0 ; i < bitscount ; i ++ ) { let p ; if ( x1 == 0 && y1 == 0 ) p = prefix_count [ i ] [ x2 ] [ y2 ] ; else if ( x1 == 0 ) p = prefix_count [ i ] [ x2 ] [ y2 ] - prefix_count [ i ] [ x2 ] [ y1 - 1 ] ; else if ( y1 == 0 ) p = prefix_count [ i ] [ x2 ] [ y2 ] - prefix_count [ i ] [ x1 - 1 ] [ y2 ] ; else p = prefix_count [ i ] [ x2 ] [ y2 ] - prefix_count [ i ] [ x1 - 1 ] [ y2 ] - prefix_count [ i ] [ x2 ] [ y1 - 1 ] + prefix_count [ i ] [ x1 - 1 ] [ y1 - 1 ] ; if ( p == ( x2 - x1 + 1 ) * ( y2 - y1 + 1 ) ) ans = ( ans | ( 1 << i ) ) ; } return ans ; } let arr = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ] ; findPrefixCount ( arr ) ; let queries = [ [ 1 , 1 , 1 , 1 ] , [ 1 , 2 , 2 , 2 ] ] ; let q = queries . length ; for ( let i = 0 ; i < q ; i ++ ) document . write ( rangeAnd ( queries [ i ] [ 0 ] , queries [ i ] [ 1 ] , queries [ i ] [ 2 ] , queries [ i ] [ 3 ] ) + " " ) ;

Index/key variables: i, j, k, x2, y2
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
var maxLen = 10 ; var dp = Array ( maxLen ) ; var v = Array ( maxLen ) ; function maxSum ( arr , i , n ) { if ( i >= n ) return 0 ; if ( v [ i ] ) return dp [ i ] ; v [ i ] = 1 ; dp [ i ] = Math . max ( maxSum ( arr , i + 1 , n ) , arr [ i ] + maxSum ( arr , i + 2 , n ) ) ; return dp [ i ] ; } var arr = [ 12 , 9 , 7 , 33 ] ; var n = arr . length ; document . write ( maxSum ( arr , 0 , n ) ) ;

Index/key variables: i
Javascript program:
let MAX = 100 ; let memo = new Array ( MAX ) ; for ( let i = 0 ; i < MAX ; i ++ ) { memo [ i ] = new Array ( MAX ) ; for ( let j = 0 ; j < MAX ; j ++ ) { memo [ i ] [ j ] = 0 ; } } function oSRec ( arr , i , j , sum ) { if ( j == i + 1 ) return Math . max ( arr [ i ] , arr [ j ] ) ; if ( memo [ i ] [ j ] != - 1 ) return memo [ i ] [ j ] ; memo [ i ] [ j ] = Math . max ( ( sum - oSRec ( arr , i + 1 , j , sum - arr [ i ] ) ) , ( sum - oSRec ( arr , i , j - 1 , sum - arr [ j ] ) ) ) ; return memo [ i ] [ j ] ; } function accumulate ( arr , start , end ) { let sum = 0 ; for ( let i = 0 ; i < arr . length ; i ++ ) sum += arr [ i ] ; return sum ; } function optimalStrategyOfGame ( arr , n ) { let sum = 0 ; sum = accumulate ( arr , 0 , n ) ; for ( let j = 0 ; j < MAX ; j ++ ) { for ( let k = 0 ; k < MAX ; k ++ ) memo [ j ] [ k ] = - 1 ; } return oSRec ( arr , 0 , n - 1 , sum ) ; } let arr1 = [ 8 , 15 , 3 , 7 ] ; let n = arr1 . length ; document . write ( optimalStrategyOfGame ( arr1 , n ) + " " ) ; let arr2 = [ 2 , 2 , 2 , 2 ] ; n = arr2 . length ; document . write ( optimalStrategyOfGame ( arr2 , n ) + " " ) ; let arr3 = [ 20 , 30 , 2 , 2 , 2 , 10 ] ; n = arr3 . length ; document . write ( optimalStrategyOfGame ( arr3 , n ) + " " ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k, sum
Iterator variables: i, j, k
Javascript program:
var N = 5 ; function func ( idx , cur , a , dp , n , x ) { if ( idx == n ) { return 0 ; } if ( dp [ idx ] [ cur ] != - 1 ) { return dp [ idx ] [ cur ] ; } var ans = 0 ; if ( cur == 0 ) { ans = Math . max ( ans , a [ idx ] + func ( idx + 1 , 0 , a , dp , n , x ) ) ; ans = Math . max ( ans , x * a [ idx ] + func ( idx + 1 , 1 , a , dp , n , x ) ) ; } else if ( cur == 1 ) { ans = Math . max ( ans , x * a [ idx ] + func ( idx + 1 , 1 , a , dp , n , x ) ) ; ans = Math . max ( ans , a [ idx ] + func ( idx + 1 , 2 , a , dp , n , x ) ) ; { ans = Math . max ( ans , a [ idx ] + func ( idx + 1 , 2 , a , dp , n , x ) ) ; } return dp [ idx ] [ cur ] = ans ; } function getMaximumSum ( a , n , x ) { var dp = Array ( n ) . fill ( ) . map ( ( ) => Array ( 3 ) . fill ( 0 ) ) ; for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < 3 ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } var maxi = 0 ; for ( i = 0 ; i < n ; i ++ ) { maxi = Math . max ( maxi , func ( i , 0 , a , dp , n , x ) ) ; } return maxi ; } var a = [ - 3 , 8 , - 2 , 1 , - 6 ] ; var n = a . length ; var x = - 1 ; document . write ( getMaximumSum ( a , n , x ) ) ;

Index/key variables: cur, i, idx, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
var N = 100 ; function pre_process ( dp , s ) { var n = s . length ; for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < n ; j ++ ) { dp [ i ] [ j ] = false ; } } for ( j = 1 ; j <= n ; j ++ ) { for ( i = 0 ; i <= n - j ; i ++ ) { if ( j <= 2 ) { if ( s [ i ] == s [ i + j - 1 ] ) { dp [ i ] [ i + j - 1 ] = true ; } } else if ( s [ i ] == s [ i + j - 1 ] ) { dp [ i ] [ i + j - 1 ] = dp [ i + 1 ] [ i + j - 2 ] ; } } } } function countPairs ( s ) { var dp = Array ( N ) . fill ( ) . map ( ( ) => Array ( N ) . fill ( false ) ) ; pre_process ( dp , s ) ; var n = s . length ; var left = Array ( n ) . fill ( 0 ) ; var right = Array ( n ) . fill ( 0 ) ; left [ 0 ] = 1 ; for ( i = 1 ; i < n ; i ++ ) { for ( j = 0 ; j <= i ; j ++ ) { if ( dp [ j ] [ i ] == true ) { left [ i ] ++ ; } } } right [ n - 1 ] = 1 ; for ( i = n - 2 ; i >= 0 ; i -- ) { right [ i ] = right [ i + 1 ] ; for ( j = n - 1 ; j >= i ; j -- ) { if ( dp [ i ] [ j ] == true ) { right [ i ] ++ ; } } } var ans = 0 ; for ( i = 0 ; i < n - 1 ; i ++ ) { ans += left [ i ] * right [ i + 1 ] ; } return ans ; } var s = " " ; document . write ( countPairs ( s ) ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
var N = 100 ; function pre_process ( dp , s ) { var n = s . length ; for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < n ; j ++ ) { dp [ i ] [ j ] = false ; } } for ( j = 1 ; j <= n ; j ++ ) { for ( i = 0 ; i <= n - j ; i ++ ) { if ( j <= 2 ) { if ( s [ i ] == s [ i + j - 1 ] ) { dp [ i ] [ i + j - 1 ] = true ; } } else if ( s [ i ] == s [ i + j - 1 ] ) { dp [ i ] [ i + j - 1 ] = dp [ i + 1 ] [ i + j - 2 ] ; } } } } function answerQuery ( l , r , dp ) { if ( dp [ l ] [ r ] ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } var s = " " ; var dp = Array ( N ) . fill ( ) . map ( ( ) => Array ( N ) . fill ( ) ) ; pre_process ( dp , s ) ; var queries = [ [ 0 , 1 ] , [ 1 , 5 ] ] ; var q = queries . length ; for ( i = 0 ; i < q ; i ++ ) { answerQuery ( queries [ i ] [ 0 ] , queries [ i ] [ 1 ] , dp ) ; }

Index/key variables: i, j, l, r
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let N = 100005 ; function LIS ( a , n ) { let dp = new Array ( ) ; let d = new Array ( ) ; let ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) { dp [ a [ i ] ] = 1 ; for ( j = 2 ; j * j <= a [ i ] ; j ++ ) { if ( a [ i ] % j == 0 ) { dp [ a [ i ] ] = Math . max ( dp [ a [ i ] ] , dp [ d [ j ] ] + 1 ) ; dp [ a [ i ] ] = Math . max ( dp [ a [ i ] ] , dp [ d [ a [ i ] / j ] ] + 1 ) ; d [ j ] = a [ i ] ; d [ a [ i ] / j ] = a [ i ] ; } } ans = Math . max ( ans , dp [ a [ i ] ] ) ; d [ a [ i ] ] = a [ i ] ; } return ans ; } let a = [ 1 , 2 , 3 , 4 , 5 , 6 ] ; let n = a . length ; document . write ( LIS ( a , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function check ( s ) { let n = s . length ; for ( let i = 2 ; i < n ; i ++ ) { if ( s [ i ] == ' ' && s [ i - 1 ] == ' ' && s [ i - 2 ] == ' ' ) return true ; } return false ; } function countStr ( i , s ) { if ( i < 0 ) { if ( check ( s ) ) return 1 ; return 0 ; } let myNameChars = s . split ( " " ) ; myNameChars [ i ] = ' ' ; s = ( myNameChars ) . join ( " " ) ; let ans = countStr ( i - 1 , s ) ; let myChar = s . split ( " " ) ; myChar [ i ] = ' ' ; s = ( myChar ) . join ( " " ) ; ans += countStr ( i - 1 , s ) ; let myChar1 = s . split ( " " ) ; myChar1 [ i ] = ' ' ; s = ( myChar1 ) . join ( " " ) ; return ans ; } let N = 4 ; let s = " " ; document . write ( countStr ( N - 1 , s ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
var n ; function solve ( i , x , dp ) { if ( i < 0 ) { return x == 3 ? 1 : 0 ; } if ( dp [ i ] [ x ] != - 1 ) { return dp [ i ] [ x ] ; } dp [ i ] [ x ] = solve ( i - 1 , 0 , dp ) ; dp [ i ] [ x ] += solve ( i - 1 , x + 1 , dp ) ; return dp [ i ] [ x ] ; } n = 4 ; var dp = Array ( n ) . fill ( ) . map ( ( ) => Array ( 4 ) . fill ( 0 ) ) ; for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < 4 ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } for ( i = 0 ; i < n ; i ++ ) { dp [ i ] [ 3 ] = ( 1 << ( i + 1 ) ) ; } document . write ( solve ( n - 1 , 0 , dp ) ) ;

Index/key variables: i, j, x
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let findSum ( n ) { let dp = new Array ( n + 1 ) ; dp [ 1 ] = 1 ; dp [ 0 ] = 0 ; for ( let i = 2 ; i <= n ; i ++ ) { dp [ i ] = ( 4 * ( i * i ) ) - 6 * ( i - 1 ) + dp [ i - 2 ] ; } return dp [ n ] ; } let n = 4 ; document . write ( findSum ( n ) ) ;

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Javascript program:
var n = 3 ; var MAX = 30 ; var dp = Array ( n ) ; for ( var i = 0 ; i < n ; i ++ ) { dp [ i ] = Array ( n ) ; for ( var j = 0 ; j < n ; j ++ ) { dp [ i ] [ j ] = Array ( MAX ) ; } } var v = Array ( n ) ; for ( var i = 0 ; i < n ; i ++ ) { v [ i ] = Array ( n ) ; for ( var j = 0 ; j < n ; j ++ ) { v [ i ] [ j ] = Array ( MAX ) ; } } function findCount ( mat , i , j , m ) { if ( i == 0 && j == 0 ) { if ( m == mat [ 0 ] [ 0 ] ) return 1 ; else return 0 ; } if ( m < 0 ) return 0 ; if ( i < 0 j < 0 ) return 0 ; if ( v [ i ] [ j ] [ m ] ) return dp [ i ] [ j ] [ m ] ; v [ i ] [ j ] [ m ] = true ; dp [ i ] [ j ] [ m ] = findCount ( mat , i - 1 , j , m - mat [ i ] [ j ] ) + findCount ( mat , i , j - 1 , m - mat [ i ] [ j ] ) ; return dp [ i ] [ j ] [ m ] ; } var mat = [ [ 1 , 1 , 1 ] , [ 1 , 1 , 1 ] , [ 1 , 1 , 1 ] ] ; var m = 5 ; document . write ( findCount ( mat , n - 1 , n - 1 , m ) ) ;

Index/key variables: i, j, m
Accumulator variables: i, j
Iterator variables: i, j