dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool areAllNegative ( vector < int > arr ) { for ( int i = 0 ; i < arr . size ( ) ; i ++ ) { if ( arr [ i ] > 0 ) return false ; } return true ; } vector < int > getRightToLeftKadane ( vector < int > arr ) { int max_so_far = 0 , max_ending_here = 0 ; int size = arr . size ( ) ; for ( int i = size - 1 ; i >= 0 ; i -- ) { max_ending_here = max_ending_here + arr [ i ] ; if ( max_ending_here < 0 ) max_ending_here = 0 ; else if ( max_so_far < max_ending_here ) max_so_far = max_ending_here ; arr [ i ] = max_so_far ; } return arr ; } vector < int > getPrefixSum ( vector < int > arr ) { for ( int i = 1 ; i < arr . size ( ) ; i ++ ) arr [ i ] = arr [ i - 1 ] + arr [ i ] ; return arr ; } int maxSumSubArr ( vector < int > a ) { int max_so_far = 0 , max_ending_here = 0 ; for ( int i = 0 ; i < a . size ( ) ; i ++ ) { max_ending_here = max_ending_here + a [ i ] ; if ( max_ending_here < 0 ) max_ending_here = 0 ; else if ( max_so_far < max_ending_here ) max_so_far = max_ending_here ; } return max_so_far ; } int maxSumSubWithOp ( vector < int > arr ) { vector < int > kadane_r_to_l = getRightToLeftKadane ( arr ) ; vector < int > prefixSum = getPrefixSum ( arr ) ; int size = arr . size ( ) ; for ( int i = 1 ; i < size ; i ++ ) { prefixSum [ i ] = max ( prefixSum [ i - 1 ] , prefixSum [ i ] ) ; } int max_subarray_sum = 0 ; for ( int i = 0 ; i < size - 1 ; i ++ ) { max_subarray_sum = max ( max_subarray_sum , prefixSum [ i ] + kadane_r_to_l [ i + 1 ] ) ; } return max_subarray_sum ; } int maxSum ( vector < int > arr , int size ) { if ( areAllNegative ( arr ) ) { return ( * max_element ( arr . begin ( ) , arr . end ( ) ) ) ; } int resSum = maxSumSubArr ( arr ) ; resSum = max ( resSum , maxSumSubWithOp ( arr ) ) ; reverse ( arr . begin ( ) , arr . end ( ) ) ; resSum = max ( resSum , maxSumSubWithOp ( arr ) ) ; return resSum ; } int main ( ) { vector < int > arr { -9 , 21 , 24 , 24 , -51 , -6 , 17 , -42 , -39 , 33 } ; int size = arr . size ( ) ; cout << maxSum ( arr , size ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int max_sum ( int a [ ] , int n ) { vector < vector < int > > dp ( n + 1 , vector < int > ( 2 , 0 ) ) ; dp [ 0 ] [ 0 ] = 0 , dp [ 0 ] [ 1 ] = -999999 ; for ( int i = 0 ; i <= n - 1 ; i ++ ) { dp [ i + 1 ] [ 0 ] = max ( dp [ i ] [ 0 ] + a [ i ] , dp [ i ] [ 1 ] - a [ i ] ) ; dp [ i + 1 ] [ 1 ] = max ( dp [ i ] [ 0 ] - a [ i ] , dp [ i ] [ 1 ] + a [ i ] ) ; } return dp [ n ] [ 0 ] ; } int main ( ) { int a [ ] = { -10 , 5 , -4 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; cout << max_sum ( a , n ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int MOD = 1000000007 ; int number_of_ways ( int arr [ ] , int n , int k ) { if ( k == 1 ) return 1 ; int dp [ k + 1 ] ; memset ( dp , -1 , sizeof dp ) ; for ( int i = 0 ; i < n ; i ++ ) dp [ arr [ i ] ] = 0 ; dp [ 0 ] = 1 ; dp [ 1 ] = ( dp [ 1 ] == -1 ) ? 1 : dp [ 1 ] ; for ( int i = 2 ; i <= k ; ++ i ) { if ( dp [ i ] == 0 ) continue ; dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] ; dp [ i ] %= MOD ; } return dp [ k ] ; } int main ( ) { int arr [ ] = { 3 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int k = 6 ; cout << number_of_ways ( arr , n , k ) ; return 0 ; }

Index/key variables: i, k
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findCount ( int n ) { return log ( n ) / log ( 2 ) + 1 ; } int main ( ) { int N = 10 ; cout << findCount ( N ) << endl ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findSetBits ( int n ) { for ( int i = 0 ; i <= n ; i ++ ) cout << __builtin_popcount ( i ) << " ▁ " ; } int main ( ) { int n = 5 ; findSetBits ( n ) ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countWays ( int n ) { vector < int > a ; int i = 1 ; while ( i <= n ) a . push_back ( i ++ ) ; int ways = 0 ; do { bool flag = ( a [ 0 ] == 1 ) ; for ( int i = 1 ; i < n ; i ++ ) { if ( abs ( a [ i ] - a [ i - 1 ] ) > 2 ) flag = 0 ; } if ( flag ) ways ++ ; } while ( next_permutation ( a . begin ( ) , a . end ( ) ) ) ; return ways ; } int main ( ) { int n = 6 ; cout << countWays ( n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc, ways
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countWays ( int n ) { int dp [ n + 1 ] ; dp [ 0 ] = 0 ; dp [ 1 ] = 1 ; dp [ 2 ] = 1 ; for ( int i = 3 ; i <= n ; i ++ ) { dp [ i ] = dp [ i - 1 ] + dp [ i - 3 ] + 1 ; } return dp [ n ] ; } int main ( ) { int n = 6 ; cout << countWays ( n ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void NumberOfShortestPaths ( int n , int m ) { int a [ n ] [ m ] ; for ( int i = 0 ; i < n ; i ++ ) memset ( a [ i ] , 0 , sizeof ( a [ i ] ) ) ; for ( int i = n - 1 ; i >= 0 ; i -- ) { for ( int j = 0 ; j < m ; j ++ ) { if ( j == 0 or i == n - 1 ) a [ i ] [ j ] = 1 ; else a [ i ] [ j ] = a [ i ] [ j - 1 ] + a [ i + 1 ] [ j ] ; } } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { cout << a [ i ] [ j ] << " ▁ " ; } cout << endl ; } } int main ( ) { int n = 5 , m = 2 ; NumberOfShortestPaths ( n , m ) ; 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 ; int Max_Sum ( int arr1 [ ] , int arr2 [ ] , int n ) { int dp [ n ] [ 2 ] ; for ( int i = 0 ; i < n ; i ++ ) { if ( i == 0 ) { dp [ i ] [ 0 ] = arr1 [ i ] ; dp [ i ] [ 1 ] = arr2 [ i ] ; continue ; } dp [ i ] [ 0 ] = max ( dp [ i - 1 ] [ 0 ] , dp [ i - 1 ] [ 1 ] + arr1 [ i ] ) ; dp [ i ] [ 1 ] = max ( dp [ i - 1 ] [ 1 ] , dp [ i - 1 ] [ 0 ] + arr2 [ i ] ) ; } return max ( dp [ n - 1 ] [ 0 ] , dp [ n - 1 ] [ 1 ] ) ; } int main ( ) { int arr1 [ ] = { 9 , 3 , 5 , 7 , 3 } ; int arr2 [ ] = { 5 , 8 , 1 , 4 , 5 } ; int n = sizeof ( arr1 ) / sizeof ( arr1 [ 0 ] ) ; cout << Max_Sum ( arr1 , arr2 , n ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool checkpossible ( int mask , int * arr , int * prefix , int n , int k ) { bool dp [ n + 1 ] [ k + 1 ] ; memset ( dp , 0 , sizeof ( dp ) ) ; dp [ 0 ] [ 0 ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= k ; j ++ ) { for ( int l = i - 1 ; l >= 0 ; -- l ) { if ( dp [ l ] [ j - 1 ] && ( ( ( prefix [ i ] - prefix [ l ] ) & mask ) == mask ) ) { dp [ i ] [ j ] = 1 ; break ; } } } } return dp [ n ] [ k ] ; } int Partition ( int arr [ ] , int n , int k ) { int prefix [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { prefix [ i ] = prefix [ i - 1 ] + arr [ i ] ; } int LOGS = 20 ; int ans = 0 ; for ( int i = LOGS ; i >= 0 ; -- i ) { if ( checkpossible ( ans | ( 1 << i ) , arr , prefix , n , k ) ) { ans = ans | ( 1 << i ) ; } } return ans ; } int main ( ) { int arr [ ] = { 0 , 1 , 2 , 7 , 10 , 23 , 21 , 6 , 8 , 7 , 3 } , k = 2 ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) - 1 ; cout << Partition ( arr , n , k ) ; return 0 ; }

Index/key variables: i, j, k, l, n
Accumulator variables: i, j, stdc
Iterator variables: i, j, l
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define RODS  3
#define N  3
int dp [ N + 1 ] [ RODS + 1 ] [ RODS + 1 ] ; void initialize ( ) { for ( int i = 0 ; i <= N ; i += 1 ) { for ( int j = 1 ; j <= RODS ; j ++ ) { for ( int k = 1 ; k <= RODS ; k += 1 ) { dp [ i ] [ j ] [ k ] = INT_MAX ; } } } } int mincost ( int idx , int src , int dest , int costs [ RODS ] [ RODS ] ) { if ( idx > N ) return 0 ; if ( dp [ idx ] [ src ] [ dest ] != INT_MAX ) return dp [ idx ] [ src ] [ dest ] ; int rem = 6 - ( src + dest ) ; int ans = INT_MAX ; int case1 = costs [ src - 1 ] [ dest - 1 ] + mincost ( idx + 1 , src , rem , costs ) + mincost ( idx + 1 , rem , dest , costs ) ; int case2 = costs [ src - 1 ] [ rem - 1 ] + mincost ( idx + 1 , src , dest , costs ) + mincost ( idx + 1 , dest , src , costs ) + costs [ rem - 1 ] [ dest - 1 ] + mincost ( idx + 1 , src , dest , costs ) ; ans = min ( case1 , case2 ) ; dp [ idx ] [ src ] [ dest ] = ans ; return ans ; } int main ( ) { int costs [ RODS ] [ RODS ] = { { 0 , 1 , 2 } , { 2 , 0 , 1 } , { 3 , 2 , 0 } } ; initialize ( ) ; cout << mincost ( 1 , 1 , 3 , costs ) ; return 0 ; }

Index/key variables: RODS, dest, i, idx, j, k, src
Accumulator variables: i, j, k, stdc
Iterator variables: i, j, k
C++ program:
#include <iostream>
using namespace std ; #define C  5
#define R  3
#define INT_MAX  10000000
int table [ R ] [ C ] = { 0 } ; int visited [ R ] [ C ] = { 0 } ; int min ( int p , int q , int r , int s ) { int temp1 = p < q ? p : q ; int temp2 = r < s ? r : s ; if ( temp1 < temp2 ) return temp1 ; return temp2 ; } int Distance ( int arr [ R ] [ C ] , int i , int j ) { if ( i >= R j >= C i < 0 j < 0 ) return INT_MAX ; else if ( arr [ i ] [ j ] == 0 ) { table [ i ] [ j ] = INT_MAX ; return INT_MAX ; } else if ( arr [ i ] [ j ] == 2 ) { table [ i ] [ j ] = 0 ; return 0 ; } else if ( visited [ i ] [ j ] ) { return INT_MAX ; } else { visited [ i ] [ j ] = 1 ; int temp1 = Distance ( arr , i + 1 , j ) ; int temp2 = Distance ( arr , i - 1 , j ) ; int temp3 = Distance ( arr , i , j + 1 ) ; int temp4 = Distance ( arr , i , j - 1 ) ; int min_value = 1 + min ( temp1 , temp2 , temp3 , temp4 ) ; if ( table [ i ] [ j ] > 0 && table [ i ] [ j ] < INT_MAX ) { if ( min_value < table [ i ] [ j ] ) table [ i ] [ j ] = min_value ; } else table [ i ] [ j ] = min_value ; visited [ i ] [ j ] = 0 ; return table [ i ] [ j ] ; } } int minTime ( int arr [ ] [ C ] ) { int max = 0 ; for ( int i = 0 ; i < R ; i ++ ) { for ( int j = 0 ; j < C ; j ++ ) { if ( arr [ i ] [ j ] == 1 ) Distance ( arr , i , j ) ; } } for ( int i = 0 ; i < R ; i ++ ) { for ( int j = 0 ; j < C ; j ++ ) { if ( arr [ i ] [ j ] == 1 && table [ i ] [ j ] > max ) max = table [ i ] [ j ] ; } } if ( max < INT_MAX ) return max ; return -1 ; } int main ( ) { int arr [ R ] [ C ] = { { 2 , 1 , 0 , 2 , 1 } , { 0 , 0 , 1 , 2 , 1 } , { 1 , 0 , 0 , 2 , 1 } } ; cout << minTime ( arr ) ; return 0 ; }

Index/key variables: C, R, i, j
Accumulator variables: i, j
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
#define maxLen  10
using namespace std ; int dp [ maxLen ] ; bool visit [ maxLen ] ; int maxSum ( int arr [ ] , int i , int n , int k ) { if ( i >= n ) return 0 ; if ( visit [ i ] ) return dp [ i ] ; visit [ i ] = 1 ; int tot = 0 ; dp [ i ] = maxSum ( arr , i + 1 , n , k ) ; for ( int j = i ; j < i + k and j < n ; j ++ ) { tot += arr [ j ] ; dp [ i ] = max ( dp [ i ] , tot + maxSum ( arr , j + 2 , n , k ) ) ; } return dp [ i ] ; } int main ( ) { int arr [ ] = { -1 , 2 , -3 , 4 , 5 } ; int k = 2 ; int n = sizeof ( arr ) / sizeof ( int ) ; cout << maxSum ( arr , 0 , n , k ) ; return 0 ; }

Index/key variables: i, j, maxLen
Accumulator variables: j, stdc, tot
Iterator variables: j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int dp [ 1024 ] ; int get_binary ( int u ) { int ans = 0 ; while ( u ) { int rem = u % 10 ; ans |= ( 1 << rem ) ; u /= 10 ; } return ans ; } int recur ( int u , int array [ ] , int n ) { if ( u == 0 ) return 0 ; if ( dp [ u ] != -1 ) return dp [ u ] ; int temp = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int mask = get_binary ( array [ i ] ) ; if ( ( mask u ) == u ) { dp [ u ] = max ( max ( 0 , dp [ u ^ mask ] ) + array [ i ] , dp [ u ] ) ; } } return dp [ u ] ; } int solve ( int array [ ] , int n ) { for ( int i = 0 ; i < ( 1 << 10 ) ; i ++ ) { dp [ i ] = -1 ; } int ans = 0 ; for ( int i = 0 ; i < ( 1 << 10 ) ; i ++ ) { ans = max ( ans , recur ( i , array , n ) ) ; } return ans ; } int main ( ) { int array [ ] = { 22 , 132 , 4 , 45 , 12 , 223 } ; int n = sizeof ( array ) / sizeof ( array [ 0 ] ) ; cout << solve ( array , n ) ; }

Index/key variables: i, u
Accumulator variables: ans, i, stdc, u
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define SIZE  3
const int N = 3 ; int minSum ( int A [ ] , int B [ ] , int C [ ] , int i , int n , int curr , int dp [ SIZE ] [ N ] ) { if ( n <= 0 ) return 0 ; if ( dp [ n ] [ curr ] != -1 ) return dp [ n ] [ curr ] ; if ( curr == 0 ) { return dp [ n ] [ curr ] = min ( B [ i ] + minSum ( A , B , C , i + 1 , n - 1 , 1 , dp ) , C [ i ] + minSum ( A , B , C , i + 1 , n - 1 , 2 , dp ) ) ; } if ( curr == 1 ) return dp [ n ] [ curr ] = min ( A [ i ] + minSum ( A , B , C , i + 1 , n - 1 , 0 , dp ) , C [ i ] + minSum ( A , B , C , i + 1 , n - 1 , 2 , dp ) ) ; return dp [ n ] [ curr ] = min ( A [ i ] + minSum ( A , B , C , i + 1 , n - 1 , 0 , dp ) , B [ i ] + minSum ( A , B , C , i + 1 , n - 1 , 1 , dp ) ) ; } int main ( ) { int A [ ] = { 1 , 50 , 1 } ; int B [ ] = { 50 , 50 , 50 } ; int C [ ] = { 50 , 50 , 50 } ; int dp [ SIZE ] [ N ] ; for ( int i = 0 ; i < SIZE ; i ++ ) for ( int j = 0 ; j < N ; j ++ ) dp [ i ] [ j ] = -1 ; cout << min ( A [ 0 ] + minSum ( A , B , C , 1 , SIZE - 1 , 0 , dp ) , min ( B [ 0 ] + minSum ( A , B , C , 1 , SIZE - 1 , 1 , dp ) , C [ 0 ] + minSum ( A , B , C , 1 , SIZE - 1 , 2 , dp ) ) ) ; return 0 ; }

Index/key variables: N, SIZE, curr, i, j, n
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define n  3
int dp [ n ] [ n ] [ 2 ] ; bool v [ n ] [ n ] [ 2 ] ; int max ( int a , int b , int c ) { int m = a ; if ( m < b ) m = b ; if ( m < c ) m = c ; return m ; } int maxScore ( int arr [ ] [ n ] , int i , int j , int s ) { if ( i > n - 1 i < 0 j > n - 1 ) return 0 ; if ( i == 0 and j == n - 1 ) return arr [ i ] [ j ] ; if ( v [ i ] [ j ] [ s ] ) return dp [ i ] [ j ] [ s ] ; v [ i ] [ j ] [ s ] = 1 ; if ( ! s ) dp [ i ] [ j ] [ s ] = arr [ i ] [ j ] + max ( maxScore ( arr , i + 1 , j , s ) , maxScore ( arr , i , j + 1 , s ) , maxScore ( arr , i - 1 , j , ! s ) ) ; else dp [ i ] [ j ] [ s ] = arr [ i ] [ j ] + max ( maxScore ( arr , i - 1 , j , s ) , maxScore ( arr , i , j + 1 , s ) ) ; return dp [ i ] [ j ] [ s ] ; } int main ( ) { int arr [ n ] [ n ] = { { 1 , 1 , 1 } , { 1 , 5 , 1 } , { 1 , 1 , 1 } } ; cout << maxScore ( arr , 0 , 0 , 0 ) ; return 0 ; }

Index/key variables: i, j, n, s
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int MaximumMarks ( int marksarr [ ] , int timearr [ ] , int h , int n , int p ) { int no_of_topics = n + 1 ; int total_time = h + 1 ; int T [ no_of_topics ] [ total_time ] ; for ( int i = 0 ; i < no_of_topics ; i ++ ) { T [ i ] [ 0 ] = 0 ; } for ( int j = 0 ; j < total_time ; j ++ ) { T [ 0 ] [ j ] = 0 ; } for ( int i = 1 ; i < no_of_topics ; i ++ ) { for ( int j = 1 ; j < total_time ; j ++ ) { if ( j < timearr [ i ] ) { T [ i ] [ j ] = T [ i - 1 ] [ j ] ; } else { T [ i ] [ j ] = max ( marksarr [ i ] + T [ i - 1 ] [ j - timearr [ i ] ] , T [ i - 1 ] [ j ] ) ; } } } int i = no_of_topics - 1 , j = total_time - 1 ; int sum = 0 ; while ( i > 0 && j > 0 ) { if ( T [ i ] [ j ] == T [ i - 1 ] [ j ] ) { i -- ; } else { sum += timearr [ i ] ; j -= timearr [ i ] ; i -- ; } } int marks = T [ no_of_topics - 1 ] [ total_time - 1 ] ; if ( marks < p ) return -1 ; return sum ; } int main ( ) { int n = 4 , h = 10 , p = 10 ; int marksarr [ n + 1 ] = { 0 , 6 , 4 , 2 , 8 } ; int timearr [ n + 1 ] = { 0 , 4 , 6 , 2 , 7 } ; cout << MaximumMarks ( marksarr , timearr , h , n , p ) ; return 0 ; }

Index/key variables: i, j, no_of_topics, total_time
Accumulator variables: i, j, stdc, sum
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
#define maxLen  10
#define maskLen  130
using namespace std ; int dp [ maxLen ] [ maskLen ] ; bool v [ maxLen ] [ maskLen ] ; int minSteps ( int arr [ ] , int i , int mask , int n ) { if ( i == n - 1 ) return 0 ; if ( i > n - 1 i < 0 ) return 9999999 ; if ( ( mask >> i ) & 1 ) return 9999999 ; if ( v [ i ] [ mask ] ) return dp [ i ] [ mask ] ; v [ i ] [ mask ] = 1 ; dp [ i ] [ mask ] = 1 + min ( minSteps ( arr , i - arr [ i ] , ( mask | ( 1 << i ) ) , n ) , minSteps ( arr , i + arr [ i ] , ( mask | ( 1 << i ) ) , n ) ) ; return dp [ i ] [ mask ] ; } int main ( ) { int arr [ ] = { 1 , 2 , 2 , 2 , 1 , 1 } ; int n = sizeof ( arr ) / sizeof ( int ) ; int ans = minSteps ( arr , 0 , 0 , n ) ; if ( ans >= 9999999 ) cout << -1 ; else cout << ans ; }

Index/key variables: i, mask, maskLen, maxLen
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int oSRec ( int arr [ ] , int i , int j , int sum ) { if ( j == i + 1 ) return max ( arr [ i ] , arr [ j ] ) ; return max ( ( sum - oSRec ( arr , i + 1 , j , sum - arr [ i ] ) ) , ( sum - oSRec ( arr , i , j - 1 , sum - arr [ j ] ) ) ) ; } int optimalStrategyOfGame ( int * arr , int n ) { int sum = 0 ; sum = accumulate ( arr , arr + n , sum ) ; return oSRec ( arr , 0 , n - 1 , sum ) ; } int main ( ) { int arr1 [ ] = { 8 , 15 , 3 , 7 } ; int n = sizeof ( arr1 ) / sizeof ( arr1 [ 0 ] ) ; printf ( " % d STRNEWLINE " , optimalStrategyOfGame ( arr1 , n ) ) ; int arr2 [ ] = { 2 , 2 , 2 , 2 } ; n = sizeof ( arr2 ) / sizeof ( arr2 [ 0 ] ) ; printf ( " % d STRNEWLINE " , optimalStrategyOfGame ( arr2 , n ) ) ; int arr3 [ ] = { 20 , 30 , 2 , 2 , 2 , 10 } ; n = sizeof ( arr3 ) / sizeof ( arr3 [ 0 ] ) ; printf ( " % d STRNEWLINE " , optimalStrategyOfGame ( arr3 , n ) ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define ll  unsigned long long
bool ispower ( ll n ) { if ( n < 125 ) return ( n == 1 n == 5 n == 25 ) ; if ( n % 125 != 0 ) return false ; else return ispower ( n / 125 ) ; } ll number ( string s , int i , int j ) { ll ans = 0 ; for ( int x = i ; x < j ; x ++ ) { ans = ans * 2 + ( s [ x ] - '0' ) ; } return ans ; } int minCuts ( string s , int n ) { int dp [ n + 1 ] ; memset ( dp , n + 1 , sizeof ( dp ) ) ; dp [ 0 ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { if ( s [ i - 1 ] == '0' ) continue ; for ( int j = 0 ; j < i ; j ++ ) { if ( s [ j ] == '0' ) continue ; ll num = number ( s , j , i ) ; if ( ! ispower ( num ) ) continue ; dp [ i ] = min ( dp [ i ] , dp [ j ] + 1 ) ; } } return ( ( dp [ n ] < n + 1 ) ? dp [ n ] : -1 ) ; } int main ( ) { string s = "101101101" ; int n = s . length ( ) ; cout << minCuts ( s , n ) ; return 0 ; }

Index/key variables: i, j, n, x
Accumulator variables: i, j, stdc, x
Iterator variables: i, j, x
C++ program:
#include <iostream>
using namespace std ; int MinOfCubed ( int k ) { if ( k < 8 ) return k ; int res = k ; for ( int i = 1 ; i <= k ; i ++ ) { if ( ( i * i * i ) > k ) return res ; res = min ( res , MinOfCubed ( k - ( i * i * i ) ) + 1 ) ; } return res ; } int main ( ) { int num = 15 ; cout << MinOfCubed ( num ) ; return 0 ; }

Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int MinOfCubedDP ( int k ) { int * DP = new int [ k + 1 ] , j = 1 , t = 1 ; DP [ 0 ] = 0 ; for ( int i = 1 ; i <= k ; i ++ ) { DP [ i ] = INT_MAX ; while ( j <= i ) { if ( j == i ) DP [ i ] = 1 ; else if ( DP [ i ] > DP [ i - j ] ) DP [ i ] = DP [ i - j ] + 1 ; t ++ ; j = t * t * t ; } t = j = 1 ; } return DP [ k ] ; } int main ( ) { int num = 15 ; cout << MinOfCubedDP ( num ) ; return 0 ; }

Index/key variables: i, k
Accumulator variables: i, stdc, t
Iterator variables: i
C++ program:
#include <algorithm>
#include <iostream>
using namespace std ; int maxSum ( int a [ ] , int n ) { int ans = 0 ; int * arr = new int [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) arr [ i ] = a [ i - 1 ] ; int * * dp = new int * [ n + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) dp [ i ] = new int [ 3 ] ; for ( int i = 1 ; i <= n ; ++ i ) { dp [ i ] [ 0 ] = max ( arr [ i ] , dp [ i - 1 ] [ 0 ] + arr [ i ] ) ; dp [ i ] [ 1 ] = max ( 0 , dp [ i - 1 ] [ 0 ] ) - arr [ i ] ; if ( i >= 2 ) dp [ i ] [ 1 ] = max ( dp [ i ] [ 1 ] , dp [ i - 1 ] [ 1 ] + arr [ i ] ) ; if ( i >= 2 ) dp [ i ] [ 2 ] = dp [ i - 1 ] [ 1 ] - arr [ i ] ; if ( i >= 3 ) dp [ i ] [ 2 ] = max ( dp [ i ] [ 2 ] , dp [ i - 1 ] [ 2 ] + arr [ i ] ) ; ans = max ( ans , dp [ i ] [ 0 ] ) ; ans = max ( ans , dp [ i ] [ 1 ] ) ; ans = max ( ans , dp [ i ] [ 2 ] ) ; } return ans ; } int main ( ) { int arr [ ] = { -5 , 3 , 2 , 7 , -8 , 3 , 7 , -9 , 10 , 12 , -6 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << maxSum ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxSum ( int * arr , int k , int n ) { if ( n == 0 ) return 0 ; if ( n == 1 ) return arr [ 0 ] ; if ( n == 2 ) return max ( arr [ 0 ] , arr [ 1 ] ) ; int dp [ n ] ; dp [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i <= k ; i ++ ) dp [ i ] = max ( arr [ i ] , dp [ i - 1 ] ) ; for ( int i = k + 1 ; i < n ; i ++ ) dp [ i ] = max ( arr [ i ] , dp [ i - ( k + 1 ) ] + arr [ i ] ) ; int max = * ( std :: max_element ( dp , dp + n ) ) ; return max ; } int main ( ) { int arr [ ] = { 6 , 7 , 1 , 3 , 8 , 2 , 4 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int k = 2 ; cout << maxSum ( arr , k , n ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int MinimumCost ( int a [ ] , int n , int x ) { for ( int i = 1 ; i < n ; i ++ ) { a [ i ] = min ( a [ i ] , 2 * a [ i - 1 ] ) ; } int ind = 0 ; int sum = 0 ; while ( x ) { if ( x & 1 ) sum += a [ ind ] ; ind ++ ; x = x >> 1 ; } return sum ; } int main ( ) { int a [ ] = { 20 , 50 , 60 , 90 } ; int x = 7 ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; cout << MinimumCost ( a , n , x ) ; return 0 ; }

Index/key variables: i, ind
Accumulator variables: i, ind, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countWays ( int n , int l , int r ) { int tL = l , tR = r ; int L [ 2 ] = { 0 } , R [ 2 ] = { 0 } ; L [ l % 2 ] = l , R [ r % 2 ] = r ; l ++ , r -- ; if ( l <= tR && r >= tL ) L [ l % 2 ] = l , R [ r % 2 ] = r ; int cnt0 = 0 , cnt1 = 0 ; if ( R [ 0 ] && L [ 0 ] ) cnt0 = ( R [ 0 ] - L [ 0 ] ) / 2 + 1 ; if ( R [ 1 ] && L [ 1 ] ) cnt1 = ( R [ 1 ] - L [ 1 ] ) / 2 + 1 ; int dp [ n ] [ 2 ] ; dp [ 1 ] [ 0 ] = cnt0 ; dp [ 1 ] [ 1 ] = cnt1 ; for ( int i = 2 ; i <= n ; i ++ ) { dp [ i ] [ 0 ] = ( cnt0 * dp [ i - 1 ] [ 0 ] + cnt1 * dp [ i - 1 ] [ 1 ] ) ; dp [ i ] [ 1 ] = ( cnt0 * dp [ i - 1 ] [ 1 ] + cnt1 * dp [ i - 1 ] [ 0 ] ) ; } return dp [ n ] [ 0 ] ; } int main ( ) { int n = 2 , l = 1 , r = 3 ; cout << countWays ( n , l , r ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i, l, r, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int M = 1001 ; const int MOD = 998244353 ; int dp [ M ] [ M ] ; int solve ( int idx , int diff , int N , int M , int K ) { if ( idx > N ) { if ( diff == K ) return 1 ; return 0 ; } if ( dp [ idx ] [ diff ] != -1 ) return dp [ idx ] [ diff ] ; int ans = solve ( idx + 1 , diff , N , M , K ) ; ans += ( M - 1 ) * solve ( idx + 1 , diff + 1 , N , M , K ) ; return dp [ idx ] [ diff ] = ans % MOD ; } int main ( ) { int N = 3 , M = 3 , K = 0 ; memset ( dp , -1 , sizeof ( dp ) ) ; cout << ( M * solve ( 2 , 0 , N , M , K ) ) << endl ; return 0 ; }

Index/key variables: M, diff, idx
Accumulator variables: ans, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define N  3
int maxPathSum ( int tri [ ] [ N ] ) { int ans = 0 ; for ( int i = N - 2 ; i >= 0 ; i -- ) { for ( int j = 0 ; j < N - i ; j ++ ) { if ( j - 1 >= 0 ) tri [ i ] [ j ] += max ( tri [ i + 1 ] [ j ] , tri [ i + 1 ] [ j - 1 ] ) ; else tri [ i ] [ j ] += tri [ i + 1 ] [ j ] ; ans = max ( ans , tri [ i ] [ j ] ) ; } } return ans ; } int main ( ) { int tri [ N ] [ N ] = { { 1 , 5 , 3 } , { 4 , 8 , 0 } , { 1 , 0 , 0 } } ; cout << maxPathSum ( tri ) ; return 0 ; }

Index/key variables: N, i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j