dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int maxn = 16 ; vector < int > precompute ( ) { vector < int > dp ( maxn , -1 ) ; dp [ 0 ] = 0 ; for ( int i = 1 ; i < maxn ; ++ i ) { for ( auto j : vector < int > { 4 , 6 , 9 } ) { if ( i >= j && dp [ i - j ] != -1 ) { dp [ i ] = max ( dp [ i ] , dp [ i - j ] + 1 ) ; } } } return dp ; } int Maximum_Summands ( vector < int > dp , int n ) { if ( n < maxn ) return dp [ n ] ; else { int t = ( n - maxn ) / 4 + 1 ; return t + dp [ n - 4 * t ] ; } } int main ( ) { int n = 12 ; vector < int > dp = precompute ( ) ; cout << Maximum_Summands ( dp , n ) << endl ; return 0 ; }

Index/key variables: i, n
Accumulator variables: stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int min ( int a , int b ) { return ( a > b ) ? b : a ; } int minCostJumpsDP ( vector < int > & A , int k ) { int size = A . size ( ) ; vector < int > x ( size , INT_MAX ) ; x [ 0 ] = 0 ; for ( int i = 0 ; i < size ; i ++ ) { for ( int j = i + 1 ; j < i + k + 1 ; j ++ ) { x [ j ] = min ( x [ j ] , x [ i ] + abs ( A [ i ] - A [ j ] ) ) ; } } return x [ size - 1 ] ; } int main ( ) { vector < int > input { 83 , 26 , 37 , 35 , 33 , 35 , 56 } ; cout << minCostJumpsDP ( input , 3 ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int diameter = -1 ; int dfs ( int node , int parent , int dp1 [ ] , int dp2 [ ] , list < int > * adj ) { int firstmax = -1 ; int secondmax = -1 ; for ( auto i = adj [ node ] . begin ( ) ; i != adj [ node ] . end ( ) ; ++ i ) { if ( * i == parent ) continue ; dfs ( * i , node , dp1 , dp2 , adj ) ; if ( firstmax == -1 ) { firstmax = dp1 [ * i ] ; } else if ( dp1 [ * i ] >= firstmax ) { secondmax = firstmax ; firstmax = dp1 [ * i ] ; } { secondmax = dp1 [ * i ] ; } } dp1 [ node ] = 1 ; dp1 [ node ] += firstmax ; if ( secondmax != -1 ) dp2 [ node ] = 1 + firstmax + secondmax ; return max ( dp1 [ node ] , dp2 [ node ] ) ; } int main ( ) { int n = 5 ; list < int > * adj = new list < int > [ n + 1 ] ; adj [ 1 ] . push_back ( 2 ) ; adj [ 2 ] . push_back ( 1 ) ; adj [ 1 ] . push_back ( 3 ) ; adj [ 3 ] . push_back ( 1 ) ; adj [ 2 ] . push_back ( 4 ) ; adj [ 4 ] . push_back ( 2 ) ; adj [ 2 ] . push_back ( 5 ) ; adj [ 5 ] . push_back ( 2 ) ; int dp1 [ n + 1 ] , dp2 [ n + 1 ] ; memset ( dp1 , 0 , sizeof dp1 ) ; memset ( dp2 , 0 , sizeof dp2 ) ; cout << " Diameter ▁ of ▁ the ▁ given ▁ tree ▁ is ▁ " << dfs ( 1 , 1 , dp1 , dp2 , adj ) << endl ; return 0 ; }

Index/key variables: node
Accumulator variables: stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define ll  long long int
#define N  4
int getSum ( int r1 , int r2 , int c1 , int c2 , int dp [ N + 1 ] [ N + 1 ] ) { return dp [ r2 ] [ c2 ] - dp [ r2 ] [ c1 ] - dp [ r1 ] [ c2 ] + dp [ r1 ] [ c1 ] ; } bool sumFound ( int K , int S , int grid [ N ] [ N ] ) { int dp [ N + 1 ] [ N + 1 ] ; for ( int i = 0 ; i < N ; i ++ ) for ( int j = 0 ; j < N ; j ++ ) dp [ i + 1 ] [ j + 1 ] = dp [ i + 1 ] [ j ] + dp [ i ] [ j + 1 ] - dp [ i ] [ j ] + grid [ i ] [ j ] ; for ( int i = 0 ; i < N ; i ++ ) for ( int j = 0 ; j < N ; j ++ ) { int sum = getSum ( i , i + K , j , j + K , dp ) ; if ( sum == S ) return true ; } return false ; } int main ( ) { int grid [ N ] [ N ] = { { 1 , 2 , 3 , 4 } , { 5 , 6 , 7 , 8 } , { 9 , 10 , 11 , 12 } , { 13 , 14 , 15 , 16 } } ; int K = 2 ; int S = 14 ; if ( sumFound ( K , S , grid ) ) cout << " Yes " << endl ; else cout << " No " << endl ; }

Index/key variables: N, c1, c2, i, j, r1, r2
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void bfs ( int n , int m , int num ) { queue < int > q ; q . push ( num ) ; while ( ! q . empty ( ) ) { int stepNum = q . front ( ) ; q . pop ( ) ; if ( stepNum <= m && stepNum >= n ) cout << stepNum << " ▁ " ; if ( num == 0 stepNum > m ) continue ; int lastDigit = stepNum % 10 ; int stepNumA = stepNum * 10 + ( lastDigit - 1 ) ; int stepNumB = stepNum * 10 + ( lastDigit + 1 ) ; if ( lastDigit == 0 ) q . push ( stepNumB ) ; else if ( lastDigit == 9 ) q . push ( stepNumA ) ; else { q . push ( stepNumA ) ; q . push ( stepNumB ) ; } } } void displaySteppingNumbers ( int n , int m ) { for ( int i = 0 ; i <= 9 ; i ++ ) bfs ( n , m , i ) ; } int main ( ) { int n = 0 , m = 21 ; displaySteppingNumbers ( n , m ) ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define row  5
#define col  5
int minDistance [ row + 1 ] [ col + 1 ] , visited [ row + 1 ] [ col + 1 ] ; queue < pair < int , int > > que ; bool isValid ( int grid [ ] [ col ] , int i , int j ) { if ( i < 0 j < 0 j > = col i > = row grid [ i ] [ j ] visited [ i ] [ j ] ) return false ; return true ; } int findMinPathminDistance ( int grid [ ] [ col ] , int sourceRow , int sourceCol ) { if ( sourceCol == 0 sourceCol == col - 1 sourceRow == 0 sourceRow == row - 1 ) return 0 ; int minFromSource = row * col ; for ( int i = 0 ; i < row ; i ++ ) for ( int j = 0 ; j < col ; j ++ ) minDistance [ i ] [ j ] = row * col ; que . push ( make_pair ( sourceRow , sourceCol ) ) ; minDistance [ sourceRow ] [ sourceCol ] = 0 ; visited [ sourceRow ] [ sourceCol ] = 1 ; while ( ! que . empty ( ) ) { pair < int , int > cell = que . front ( ) ; int cellRow = cell . first ; int cellCol = cell . second ; if ( isValid ( grid , cellRow + 1 , cellCol ) ) { que . push ( make_pair ( cellRow + 1 , cellCol ) ) ; minDistance [ cellRow + 1 ] [ cellCol ] = min ( minDistance [ cellRow + 1 ] [ cellCol ] , minDistance [ cellRow ] [ cellCol ] + 1 ) ; visited [ cellRow + 1 ] [ cellCol ] = 1 ; } if ( isValid ( grid , cellRow - 1 , cellCol ) ) { que . push ( make_pair ( cellRow - 1 , cellCol ) ) ; minDistance [ cellRow - 1 ] [ cellCol ] = min ( minDistance [ cellRow - 1 ] [ cellCol ] , minDistance [ cellRow ] [ cellCol ] + 1 ) ; visited [ cellRow - 1 ] [ cellCol ] = 1 ; } if ( isValid ( grid , cellRow , cellCol + 1 ) ) { que . push ( make_pair ( cellRow , cellCol + 1 ) ) ; minDistance [ cellRow ] [ cellCol + 1 ] = min ( minDistance [ cellRow ] [ cellCol + 1 ] , minDistance [ cellRow ] [ cellCol ] + 1 ) ; visited [ cellRow ] [ cellCol + 1 ] = 1 ; } if ( isValid ( grid , cellRow , cellCol - 1 ) ) { que . push ( make_pair ( cellRow , cellCol - 1 ) ) ; minDistance [ cellRow ] [ cellCol - 1 ] = min ( minDistance [ cellRow ] [ cellCol - 1 ] , minDistance [ cellRow ] [ cellCol ] + 1 ) ; visited [ cellRow ] [ cellCol - 1 ] = 1 ; } que . pop ( ) ; } int i ; for ( i = 0 ; i < col ; i ++ ) minFromSource = min ( minFromSource , minDistance [ 0 ] [ i ] ) ; for ( i = 0 ; i < col ; i ++ ) minFromSource = min ( minFromSource , minDistance [ row - 1 ] [ i ] ) ; for ( i = 0 ; i < row ; i ++ ) minFromSource = min ( minFromSource , minDistance [ i ] [ 0 ] ) ; for ( i = 0 ; i < row ; i ++ ) minFromSource = min ( minFromSource , minDistance [ i ] [ col - 1 ] ) ; if ( minFromSource == row * col ) return -1 ; return minFromSource ; } int main ( ) { int sourceRow = 3 , sourceCol = 3 ; int grid [ row ] [ col ] = { 1 , 1 , 1 , 1 , 0 , 0 , 0 , 1 , 0 , 1 , 0 , 0 , 1 , 0 , 1 , 1 , 0 , 0 , 0 , 1 , 1 , 1 , 0 , 1 , 0 } ; cout << findMinPathminDistance ( grid , sourceRow , sourceCol ) ; return 0 ; }

Index/key variables: cellCol, cellRow, col, i, j, row, sourceCol, sourceRow
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findMinOperations ( string S ) { reverse ( S . begin ( ) , S . end ( ) ) ; int n = S . length ( ) ; int dp [ n + 1 ] [ 2 ] ; if ( S [ 0 ] == '0' ) { dp [ 0 ] [ 0 ] = 0 ; } else { dp [ 0 ] [ 0 ] = 1 ; } dp [ 0 ] [ 1 ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { if ( S [ i ] == '0' ) { dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] ; dp [ i ] [ 1 ] = 1 + min ( dp [ i - 1 ] [ 1 ] , dp [ i - 1 ] [ 0 ] ) ; } else { dp [ i ] [ 1 ] = dp [ i - 1 ] [ 1 ] ; dp [ i ] [ 0 ] = 1 + min ( dp [ i - 1 ] [ 0 ] , dp [ i - 1 ] [ 1 ] ) ; } } return dp [ n - 1 ] [ 0 ] ; } int main ( ) { string S = "100" ; cout << findMinOperations ( S ) << endl ; S = "111" ; cout << findMinOperations ( S ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void solve ( int N , int K ) { vector < long long int > Array ( N + 1 , 0 ) ; if ( N <= K ) { cout << "1" << endl ; return ; } long long int i = 0 , sum = K ; for ( i = 1 ; i <= K ; ++ i ) { Array [ i ] = 1 ; } Array [ i ] = sum ; for ( int i = K + 2 ; i <= N ; ++ i ) { Array [ i ] = sum - Array [ i - K - 1 ] + Array [ i - 1 ] ; sum = Array [ i ] ; } cout << Array [ N ] << endl ; } int main ( ) { long long int N = 4 , K = 2 ; solve ( N , K ) ; return 0 ; }

Index/key variables: N, i
Accumulator variables: stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MAX_VAL  10000000
int dp [ 100 ] [ 100 ] ; int find ( int index , int openbrk , int n , int adj [ ] [ 2 ] ) { if ( openbrk < 0 ) return MAX_VAL ; if ( index == n ) { if ( openbrk == 0 ) { return 0 ; } return MAX_VAL ; } if ( dp [ index ] [ openbrk ] != -1 ) return dp [ index ] [ openbrk ] ; dp [ index ] [ openbrk ] = min ( adj [ index ] [ 1 ] + find ( index + 1 , openbrk + 1 , n , adj ) , adj [ index ] [ 0 ] + find ( index + 1 , openbrk - 1 , n , adj ) ) ; return dp [ index ] [ openbrk ] ; } int main ( ) { int n = 4 ; int adj [ n ] [ 2 ] = { { 5000 , 3000 } , { 6000 , 2000 } , { 8000 , 1000 } , { 9000 , 6000 } } ; memset ( dp , -1 , sizeof ( dp ) ) ; cout << find ( 1 , 1 , n , adj ) + adj [ 0 ] [ 1 ] << endl ; return 0 ; }

Index/key variables: index, n, openbrk
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; long getNumberOfWays ( long N , vector < long > Coins ) { vector < long > ways ( N + 1 ) ; ways [ 0 ] = 1 ; for ( int i = 0 ; i < Coins . size ( ) ; i ++ ) { for ( int j = 0 ; j < ways . size ( ) ; j ++ ) { if ( Coins [ i ] <= j ) { ways [ j ] += ways [ ( j - Coins [ i ] ) ] ; } } } return ways [ N ] ; } void printArray ( vector < long > coins ) { for ( long i : coins ) cout << i << " STRNEWLINE " ; } int main ( ) { vector < long > Coins = { 1 , 5 , 10 } ; cout << " The ▁ Coins ▁ Array : " << endl ; printArray ( Coins ) ; cout << " Solution : " << endl ; cout << getNumberOfWays ( 12 , Coins ) << endl ; }

Index/key variables: N, i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int find ( int m , int n , int adj [ ] ) { int sweet [ n + 1 ] ; int dp [ n + 1 ] [ n + 1 ] [ n + 1 ] ; sweet [ 0 ] = 0 ; for ( int i = 1 ; i <= m ; ++ i ) sweet [ i ] = adj [ i - 1 ] ; for ( int i = 0 ; i <= m ; ++ i ) { for ( int k = 0 ; k <= n ; ++ k ) dp [ i ] [ 0 ] [ k ] = 0 ; for ( int k = 1 ; k <= n ; ++ k ) dp [ i ] [ k ] [ 0 ] = -1 ; } for ( int i = 0 ; i <= m ; ++ i ) { for ( int j = 1 ; j <= n ; ++ j ) { for ( int k = 1 ; k <= n ; ++ k ) { dp [ i ] [ j ] [ k ] = -1 ; if ( i > 0 && j >= k && sweet [ k ] > 0 && dp [ i - 1 ] [ j - k ] [ k ] != -1 ) dp [ i ] [ j ] [ k ] = dp [ i - 1 ] [ j - k ] [ k ] + sweet [ k ] ; if ( dp [ i ] [ j ] [ k ] == -1 || ( dp [ i ] [ j ] [ k - 1 ] != -1 && dp [ i ] [ j ] [ k ] > dp [ i ] [ j ] [ k - 1 ] ) ) dp [ i ] [ j ] [ k ] = dp [ i ] [ j ] [ k - 1 ] ; } } } if ( dp [ m ] [ n ] [ n ] == -1 ) return 0 ; else return dp [ m ] [ n ] [ n ] ; } int main ( ) { int m = 3 ; int adj [ ] = { 2 , 1 , 3 , 0 , 4 , 10 } ; int n = sizeof ( adj ) / sizeof ( adj [ 0 ] ) ; cout << find ( m , n , adj ) ; return 0 ; }

Index/key variables: i, j, k, m, n
Accumulator variables: stdc
Iterator variables: i, j, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; int find ( int start , string adj , int n , int dp [ ] ) { if ( start == n ) return 0 ; if ( dp [ start ] != -1 ) return dp [ start ] ; dp [ start ] = 0 ; int one = 0 , zero = 0 , k ; for ( k = start ; k < n ; k ++ ) { if ( adj [ k ] == '1' ) one ++ ; else zero ++ ; if ( one > zero ) dp [ start ] = max ( dp [ start ] , find ( k + 1 , adj , n , dp ) + k - start + 1 ) ; else dp [ start ] = max ( dp [ start ] , find ( k + 1 , adj , n , dp ) ) ; } return dp [ start ] ; } int main ( ) { string adj = "100110001010001" ; int n = adj . size ( ) ; int dp [ n + 1 ] ; memset ( dp , -1 , sizeof ( dp ) ) ; cout << find ( 0 , adj , n , dp ) << endl ; return 0 ; }

Index/key variables: k, start
Accumulator variables: k, one, stdc, zero
Iterator variables: k
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isVowel ( char ch ) { if ( ch == ' a ' ch == ' e ' ch == ' i ' ch == ' o ' ch == ' u ' ) return true ; return false ; } int lcs ( char * X , char * Y , int m , int n ) { int L [ m + 1 ] [ n + 1 ] ; int i , j ; for ( i = 0 ; i <= m ; i ++ ) { for ( j = 0 ; j <= n ; j ++ ) { if ( i == 0 j == 0 ) L [ i ] [ j ] = 0 ; else if ( ( X [ i - 1 ] == Y [ j - 1 ] ) && isVowel ( X [ i - 1 ] ) ) L [ i ] [ j ] = L [ i - 1 ] [ j - 1 ] + 1 ; else L [ i ] [ j ] = max ( L [ i - 1 ] [ j ] , L [ i ] [ j - 1 ] ) ; } } return L [ m ] [ n ] ; } int main ( ) { char X [ ] = " aieef " ; char Y [ ] = " klaief " ; int m = strlen ( X ) ; int n = strlen ( Y ) ; cout << " Length ▁ of ▁ LCS ▁ = ▁ " << lcs ( X , Y , m , n ) ; return 0 ; }

Index/key variables: i, j, m, n
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool check ( int i , int val ) { if ( i - val < 0 ) return false ; return true ; } int MinimumPrimes ( int n ) { int dp [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) dp [ i ] = 1e9 ; dp [ 0 ] = dp [ 2 ] = dp [ 3 ] = dp [ 5 ] = dp [ 7 ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { if ( check ( i , 2 ) ) dp [ i ] = min ( dp [ i ] , 1 + dp [ i - 2 ] ) ; if ( check ( i , 3 ) ) dp [ i ] = min ( dp [ i ] , 1 + dp [ i - 3 ] ) ; if ( check ( i , 5 ) ) dp [ i ] = min ( dp [ i ] , 1 + dp [ i - 5 ] ) ; if ( check ( i , 7 ) ) dp [ i ] = min ( dp [ i ] , 1 + dp [ i - 7 ] ) ; } if ( dp [ n ] == ( 1e9 ) ) return -1 ; else return dp [ n ] ; } int main ( ) { int n = 12 ; int minimal = MinimumPrimes ( n ) ; if ( minimal != -1 ) cout << " Minimum ▁ number ▁ of ▁ single " << " ▁ digit ▁ primes ▁ required ▁ : ▁ " << minimal << endl ; else cout << " Not ▁ possible " ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void subsetSum ( int arr [ ] , int n , int maxSum ) { bool dp [ maxSum + 1 ] ; memset ( dp , false , sizeof dp ) ; dp [ arr [ 0 ] ] = true ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = maxSum + 1 ; j >= 1 ; j -- ) { if ( arr [ i ] <= j ) { if ( arr [ i ] == j || dp [ j ] || dp [ ( j - arr [ i ] ) ] ) dp [ j ] = true ; else dp [ j ] = false ; } } } cout << 0 << " ▁ " ; for ( int j = 0 ; j <= maxSum + 1 ; j ++ ) { if ( dp [ j ] == true ) cout << j << " ▁ " ; } } void printDistinct ( int a [ ] , int n ) { int maxSum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { maxSum += a [ i ] ; } subsetSum ( a , n , maxSum ) ; } int main ( ) { int arr [ ] = { 2 , 3 , 4 , 5 , 6 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; printDistinct ( arr , n ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, maxSum, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int size = 1000 ; int maxCost ( int a [ ] [ size ] , int m , int n ) { if ( n < 0 m < 0 ) return -1e9 ; else if ( m == 0 && n == 0 ) return 0 ; else { int num = m + n ; if ( ( num & ( num - 1 ) ) == 0 ) return a [ m ] [ n ] + maxCost ( a , m - 1 , n - 1 ) ; else return a [ m ] [ n ] + max ( maxCost ( a , m - 1 , n ) , maxCost ( a , m , n - 1 ) ) ; } } int answer ( int a [ ] [ size ] , int n ) { return maxCost ( a , n - 1 , n - 1 ) ; } int main ( ) { int a [ ] [ size ] = { { 1 , 2 , 3 , 1 } , { 4 , 5 , 6 , 1 } , { 7 , 8 , 9 , 1 } , { 1 , 1 , 1 , 1 } } ; int n = 4 ; cout << answer ( a , n ) ; return 0 ; }

Index/key variables: m, n, size
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int maximum = 1000 ; int lcs ( string X , string Y , int m , int n , int dp [ ] [ maximum ] ) { if ( m == 0 n == 0 ) return 0 ; if ( dp [ m - 1 ] [ n - 1 ] != -1 ) return dp [ m - 1 ] [ n - 1 ] ; if ( X [ m - 1 ] == Y [ n - 1 ] ) { dp [ m - 1 ] [ n - 1 ] = 1 + lcs ( X , Y , m - 1 , n - 1 , dp ) ; return dp [ m - 1 ] [ n - 1 ] ; } else { dp [ m - 1 ] [ n - 1 ] = max ( lcs ( X , Y , m , n - 1 , dp ) , lcs ( X , Y , m - 1 , n , dp ) ) ; return dp [ m - 1 ] [ n - 1 ] ; } } int main ( ) { string X = " AGGTAB " ; string Y = " GXTXAYB " ; int m = X . length ( ) ; int n = Y . length ( ) ; int dp [ m ] [ maximum ] ; memset ( dp , -1 , sizeof ( dp ) ) ; cout << " Length ▁ of ▁ LCS : ▁ " << lcs ( X , Y , m , n , dp ) ; return 0 ; }

Index/key variables: m, maximum
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void dfs ( int n , int m , int stepNum ) { if ( stepNum <= m && stepNum >= n ) cout << stepNum << " ▁ " ; if ( stepNum == 0 stepNum > m ) return ; int lastDigit = stepNum % 10 ; int stepNumA = stepNum * 10 + ( lastDigit - 1 ) ; int stepNumB = stepNum * 10 + ( lastDigit + 1 ) ; if ( lastDigit == 0 ) dfs ( n , m , stepNumB ) ; else if ( lastDigit == 9 ) dfs ( n , m , stepNumA ) ; else { dfs ( n , m , stepNumA ) ; dfs ( n , m , stepNumB ) ; } } void displaySteppingNumbers ( int n , int m ) { for ( int i = 0 ; i <= 9 ; i ++ ) dfs ( n , m , i ) ; } int main ( ) { int n = 0 , m = 21 ; displaySteppingNumbers ( n , m ) ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
int arr [ 1000 ] [ 1000 ] ; int max ( int a , int b ) ; int lcs ( char * X , char * Y , int m , int n ) { if ( m == 0 n == 0 ) return 0 ; if ( arr [ m - 1 ] [ n - 1 ] != -1 ) return arr [ m - 1 ] [ n - 1 ] ; if ( X [ m - 1 ] == Y [ n - 1 ] ) { arr [ m - 1 ] [ n - 1 ] = 1 + lcs ( X , Y , m - 1 , n - 1 ) ; return arr [ m - 1 ] [ n - 1 ] ; } else { arr [ m - 1 ] [ n - 1 ] = max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ; return arr [ m - 1 ] [ n - 1 ] ; } } int max ( int a , int b ) { return ( a > b ) ? a : b ; } int main ( ) { memset ( arr , -1 , sizeof ( arr ) ) ; char X [ ] = " AGGTAB " ; char Y [ ] = " GXTXAYB " ; int m = strlen ( X ) ; int n = strlen ( Y ) ; printf ( " Length ▁ of ▁ LCS ▁ is ▁ % d " , lcs ( X , Y , m , n ) ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int numberOfBST ( int n ) { int dp [ n + 1 ] ; fill_n ( dp , n + 1 , 0 ) ; dp [ 0 ] = 1 ; dp [ 1 ] = 1 ; for ( int i = 2 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= i ; j ++ ) { dp [ i ] = dp [ i ] + ( dp [ i - j ] * dp [ j - 1 ] ) ; } } return dp [ n ] ; } int main ( ) { int n = 3 ; cout << " Number ▁ of ▁ structurally ▁ Unique ▁ BST ▁ with ▁ " << n << " ▁ keys ▁ are ▁ : ▁ " << numberOfBST ( n ) << " STRNEWLINE " ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isPowerOf ( long val , int base ) { while ( val > 1 ) { if ( val % base != 0 ) val /= base ; } return true ; } int numberOfPartitions ( string binaryNo ) { int i , j , n = binaryNo . length ( ) ; long val ; int dp [ n ] ; dp [ n - 1 ] = ( ( binaryNo [ n - 1 ] - '0' ) == 0 ) ? -1 : 1 ; for ( i = n - 2 ; i >= 0 ; i -- ) { val = 0 ; if ( ( binaryNo [ i ] - '0' ) == 0 ) { dp [ i ] = -1 ; continue ; } dp [ i ] = INT_MAX ; for ( j = i ; j < n ; j ++ ) { val = ( val * 2 ) + ( long ) ( binaryNo [ j ] - '0' ) ; if ( isPowerOf ( val , 4 ) || isPowerOf ( val , 6 ) ) { if ( j == n - 1 ) { dp [ i ] = 1 ; } else { if ( dp [ j + 1 ] != -1 ) dp [ i ] = min ( dp [ i ] , dp [ j + 1 ] + 1 ) ; } } } if ( dp [ i ] == INT_MAX ) dp [ i ] = -1 ; } return dp [ 0 ] ; } int main ( ) { string binaryNo = "100110110" ; cout << numberOfPartitions ( binaryNo ) ; return 0 ; }

Index/key variables: i, j, n
Accumulator variables: i, j, stdc, val
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MAX  100
int summation ( int n ) { return n << ( n - 1 ) ; } int main ( ) { int n = 2 ; cout << summation ( n ) << endl ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MAX  1000
double memo [ MAX ] [ MAX ] ; double score ( int n , vector < int > & A , int k ) { if ( memo [ n ] [ k ] > 0 ) return memo [ n ] [ k ] ; double sum = 0 ; for ( int i = n - 1 ; i > 0 ; i -- ) { sum += A [ i ] ; memo [ n ] [ k ] = max ( memo [ n ] [ k ] , score ( i , A , k - 1 ) + sum / ( n - i ) ) ; } return memo [ n ] [ k ] ; } double largestSumOfAverages ( vector < int > & A , int K ) { int n = A . size ( ) ; double sum = 0 ; memset ( memo , 0.0 , sizeof ( memo ) ) ; for ( int i = 0 ; i < n ; i ++ ) { sum += A [ i ] ; memo [ i + 1 ] [ 1 ] = sum / ( i + 1 ) ; } return score ( n , A , K ) ; } int main ( ) { vector < int > A = { 9 , 1 , 2 , 3 , 9 } ; int K = 3 ; cout << largestSumOfAverages ( A , K ) << endl ; return 0 ; }

Index/key variables: MAX, i, k, n
Accumulator variables: i, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findMaxProduct ( int arr [ ] , int n ) { int i ; int ans = INT_MIN ; int maxval = 1 ; int minval = 1 ; int prevMax ; for ( i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > 0 ) { maxval = maxval * arr [ i ] ; minval = min ( 1 , minval * arr [ i ] ) ; } else if ( arr [ i ] == 0 ) { minval = 1 ; maxval = 0 ; } else if ( arr [ i ] < 0 ) { prevMax = maxval ; maxval = minval * arr [ i ] ; minval = prevMax * arr [ i ] ; } ans = max ( ans , maxval ) ; if ( maxval <= 0 ) { maxval = 1 ; } } return ans ; } int main ( ) { int arr [ ] = { 0 , -4 , 0 , -2 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << findMaxProduct ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define INF  1e9
#define MAX  50
int minMaxValues ( int arr [ ] , int n , int m ) { int sum = 0 ; for ( int i = 0 ; i < ( n + m ) ; i ++ ) { sum += arr [ i ] ; arr [ i ] += 50 ; } bool dp [ MAX + 1 ] [ MAX * MAX + 1 ] ; memset ( dp , 0 , sizeof ( dp ) ) ; dp [ 0 ] [ 0 ] = 1 ; for ( int i = 0 ; i < ( n + m ) ; i ++ ) { for ( int k = min ( n , i + 1 ) ; k >= 1 ; k -- ) { for ( int j = 0 ; j < MAX * MAX + 1 ; j ++ ) { if ( dp [ k - 1 ] [ j ] ) dp [ k ] [ j + arr [ i ] ] = 1 ; } } } int max_value = - INF , min_value = INF ; for ( int i = 0 ; i < MAX * MAX + 1 ; i ++ ) { if ( dp [ n ] [ i ] ) { int temp = i - 50 * n ; max_value = max ( max_value , temp * ( sum - temp ) ) ; min_value = min ( min_value , temp * ( sum - temp ) ) ; } } cout << " Maximum ▁ Value : ▁ " << max_value << " STRNEWLINE " << " Minimum ▁ Value : ▁ " << min_value << endl ; } int main ( ) { int n = 2 , m = 2 ; int arr [ ] = { 1 , 2 , 3 , 4 } ; minMaxValues ( arr , n , m ) ; return 0 ; }

Index/key variables: i, j, k, n
Accumulator variables: i, j, k, stdc, sum
Iterator variables: i, j, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int MAX = 1000 ; bool isPossible ( int n , int index , int sum , int M , int arr [ ] , int dp [ ] [ MAX ] ) { if ( index == n ) { if ( ( sum % M ) == 0 ) return true ; return false ; } if ( dp [ index ] [ sum ] != -1 ) return dp [ index ] [ sum ] ; bool placeAdd = isPossible ( n , index + 1 , sum + arr [ index ] , M , arr , dp ) ; bool placeMinus = isPossible ( n , index + 1 , sum - arr [ index ] , M , arr , dp ) ; bool res = ( placeAdd placeMinus ) ; dp [ index ] [ sum ] = res ; return res ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 6 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int M = 4 ; int dp [ n + 1 ] [ MAX ] ; memset ( dp , -1 , sizeof ( dp ) ) ; bool res ; res = isPossible ( n , 0 , 0 , M , arr , dp ) ; cout << ( res ? " True " : " False " ) << endl ; return 0 ; }

Index/key variables: MAX, index, sum
Accumulator variables: stdc