dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxRevenue ( int m , int x [ ] , int revenue [ ] , int n , int t ) { int maxRev [ m + 1 ] ; memset ( maxRev , 0 , sizeof ( maxRev ) ) ; int nxtbb = 0 ; for ( int i = 1 ; i <= m ; i ++ ) { if ( nxtbb < n ) { if ( x [ nxtbb ] != i ) maxRev [ i ] = maxRev [ i - 1 ] ; else { if ( i <= t ) maxRev [ i ] = max ( maxRev [ i - 1 ] , revenue [ nxtbb ] ) ; else maxRev [ i ] = max ( maxRev [ i - t - 1 ] + revenue [ nxtbb ] , maxRev [ i - 1 ] ) ; nxtbb ++ ; } } else maxRev [ i ] = maxRev [ i - 1 ] ; } return maxRev [ m ] ; } int main ( ) { int m = 20 ; int x [ ] = { 6 , 7 , 12 , 13 , 14 } ; int revenue [ ] = { 5 , 6 , 5 , 3 , 1 } ; int n = sizeof ( x ) / sizeof ( x [ 0 ] ) ; int t = 5 ; cout << maxRevenue ( m , x , revenue , n , t ) << endl ; return 0 ; }

Index/key variables: i, m, nxtbb
Accumulator variables: i, nxtbb, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
#define Row  6
#define Col  6
using namespace std ; int largestKSubmatrix ( int a [ ] [ Col ] ) { int dp [ Row ] [ Col ] ; memset ( dp , sizeof ( dp ) , 0 ) ; int result = 0 ; for ( int i = 0 ; i < Row ; i ++ ) { for ( int j = 0 ; j < Col ; j ++ ) { if ( i == 0 j == 0 ) dp [ i ] [ j ] = 1 ; else { if ( a [ i ] [ j ] == a [ i - 1 ] [ j ] && a [ i ] [ j ] == a [ i ] [ j - 1 ] && a [ i ] [ j ] == a [ i - 1 ] [ j - 1 ] ) dp [ i ] [ j ] = min ( min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) , dp [ i - 1 ] [ j - 1 ] ) + 1 ; else dp [ i ] [ j ] = 1 ; } result = max ( result , dp [ i ] [ j ] ) ; } } return result ; } int main ( ) { int a [ Row ] [ Col ] = { 2 , 2 , 3 , 3 , 4 , 4 , 5 , 5 , 7 , 7 , 7 , 4 , 1 , 2 , 7 , 7 , 7 , 4 , 4 , 4 , 7 , 7 , 7 , 4 , 5 , 5 , 5 , 1 , 2 , 7 , 8 , 7 , 9 , 4 , 4 , 4 } ; cout << largestKSubmatrix ( a ) << endl ; return 0 ; }

Index/key variables: Col, Row, i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countDivisibleSubseq ( string str , int n ) { int len = str . length ( ) ; int dp [ len ] [ n ] ; memset ( dp , 0 , sizeof ( dp ) ) ; dp [ 0 ] [ ( str [ 0 ] - '0' ) % n ] ++ ; for ( int i = 1 ; i < len ; i ++ ) { dp [ i ] [ ( str [ i ] - '0' ) % n ] ++ ; for ( int j = 0 ; j < n ; j ++ ) { dp [ i ] [ j ] += dp [ i - 1 ] [ j ] ; dp [ i ] [ ( j * 10 + ( str [ i ] - '0' ) ) % n ] += dp [ i - 1 ] [ j ] ; } } return dp [ len - 1 ] [ 0 ] ; } int main ( ) { string str = "1234" ; int n = 4 ; cout << countDivisibleSubseq ( str , n ) ; return 0 ; }

Index/key variables: i, j, len, n
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < int > findLIS ( vector < int > arr , int n ) { vector < vector < int > > L ( n ) ; L [ 0 ] . push_back ( arr [ 0 ] ) ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 0 ; j < i ; j ++ ) { if ( arr [ i ] > arr [ j ] && ( L [ i ] . size ( ) < L [ j ] . size ( ) ) ) L [ i ] = L [ j ] ; } L [ i ] . push_back ( arr [ i ] ) ; } int maxSize = 1 ; vector < int > lis ; for ( vector < int > x : L ) { if ( x . size ( ) > maxSize ) { lis = x ; maxSize = x . size ( ) ; } } return lis ; } void minimize ( int input [ ] , int n ) { vector < int > arr ( input , input + n ) ; while ( arr . size ( ) ) { vector < int > lis = findLIS ( arr , arr . size ( ) ) ; if ( lis . size ( ) < 2 ) break ; for ( int i = 0 ; i < arr . size ( ) && lis . size ( ) > 0 ; i ++ ) { if ( arr [ i ] == lis [ 0 ] ) { arr . erase ( arr . begin ( ) + i ) ; i -- ; lis . erase ( lis . begin ( ) ) ; } } } int i ; for ( i = 0 ; i < arr . size ( ) ; i ++ ) cout << arr [ i ] << " ▁ " ; if ( i == 0 ) cout << " - 1" ; } int main ( ) { int input [ ] = { 3 , 2 , 6 , 4 , 5 , 1 } ; int n = sizeof ( input ) / sizeof ( input [ 0 ] ) ; minimize ( input , n ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j, x
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MAX  21
double fact [ MAX ] ; double probability ( int k , int n ) { double ans = 0 ; for ( int i = k ; i <= n ; ++ i ) ans += fact [ n ] / ( fact [ i ] * fact [ n - i ] ) ; ans = ans / ( 1LL << n ) ; return ans ; } void precompute ( ) { fact [ 0 ] = fact [ 1 ] = 1 ; for ( int i = 2 ; i < 20 ; ++ i ) fact [ i ] = fact [ i - 1 ] * i ; } int main ( ) { precompute ( ) ; cout << probability ( 2 , 3 ) << " STRNEWLINE " ; cout << probability ( 3 , 6 ) << " STRNEWLINE " ; cout << probability ( 12 , 18 ) ; return 0 ; }

Index/key variables: MAX, i, n
Accumulator variables: ans, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countStrings ( int n , int k ) { int dp [ n + 1 ] [ k + 1 ] [ 2 ] ; memset ( dp , 0 , sizeof ( dp ) ) ; dp [ 1 ] [ 0 ] [ 0 ] = 1 ; dp [ 1 ] [ 0 ] [ 1 ] = 1 ; for ( int i = 2 ; i <= n ; i ++ ) { for ( int j = 0 ; j <= k ; j ++ ) { dp [ i ] [ j ] [ 0 ] = dp [ i - 1 ] [ j ] [ 0 ] + dp [ i - 1 ] [ j ] [ 1 ] ; dp [ i ] [ j ] [ 1 ] = dp [ i - 1 ] [ j ] [ 0 ] ; if ( j - 1 >= 0 ) dp [ i ] [ j ] [ 1 ] += dp [ i - 1 ] [ j - 1 ] [ 1 ] ; } } return dp [ n ] [ k ] [ 0 ] + dp [ n ] [ k ] [ 1 ] ; } int main ( ) { int n = 5 , k = 2 ; cout << countStrings ( n , k ) ; return 0 ; }

Index/key variables: i, j, k, n
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool canVote ( vector < int > a , int n , int x ) { int total_sum = 0 ; for ( auto x : a ) { total_sum += x ; } if ( total_sum <= x ) return true ; sort ( a . begin ( ) , a . end ( ) ) ; vector < int > presum ( a . size ( ) , 0 ) ; presum [ 0 ] = a [ 0 ] ; for ( int i = 1 ; i < presum . size ( ) ; i ++ ) { presum [ i ] = presum [ i - 1 ] + a [ i ] ; } for ( int i = 0 ; i < presum . size ( ) ; i ++ ) { for ( int j = i + 1 ; j < presum . size ( ) ; j ++ ) { int arr1_sum = ( presum [ i ] + ( total_sum - presum [ j ] ) ) ; if ( ( arr1_sum <= x ) && ( total_sum - arr1_sum ) <= x ) return true ; } } return false ; } int main ( ) { int n = 3 , x = 4 ; vector < int > a = { 2 , 4 , 2 } ; canVote ( a , n , x ) ? cout << " YES STRNEWLINE " : cout << " NO STRNEWLINE " ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc, total_sum
Iterator variables: i, j, x
C++ program:
#include <bits/stdc++.h>
using namespace std ; int dp [ 1000 ] ; int countFriendsPairings ( int n ) { if ( dp [ n ] != -1 ) return dp [ n ] ; if ( n > 2 ) return dp [ n ] = countFriendsPairings ( n - 1 ) + ( n - 1 ) * countFriendsPairings ( n - 2 ) ; else return dp [ n ] = n ; } int main ( ) { memset ( dp , -1 , sizeof ( dp ) ) ; int n = 4 ; cout << countFriendsPairings ( n ) << endl ; }

Index/key variables: n
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void preComputeFact ( vector < long long int > & fact , int n ) { for ( int i = 1 ; i <= n ; i ++ ) fact . push_back ( fact [ i - 1 ] * i ) ; } int countFriendsPairings ( vector < long long int > fact , int n ) { int ones = n , twos = 1 , ans = 0 ; while ( ones >= 0 ) { ans += fact [ n ] / ( twos * fact [ ones ] * fact [ ( n - ones ) / 2 ] ) ; ones -= 2 ; twos *= 2 ; } return ans ; } int main ( ) { vector < long long int > fact ; fact . push_back ( 1 ) ; preComputeFact ( fact , 100 ) ; int n = 4 ; cout << countFriendsPairings ( fact , n ) << endl ; return 0 ; }

Index/key variables: n, ones
Accumulator variables: ans, i, ones, stdc, twos
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define l  3
#define m  3
#define n  3
int min ( int x , int y , int z ) { return ( x < y ) ? ( ( x < z ) ? x : z ) : ( ( y < z ) ? y : z ) ; } int minPathSum ( int arr [ ] [ m ] [ n ] ) { int i , j , k ; int tSum [ l ] [ m ] [ n ] ; tSum [ 0 ] [ 0 ] [ 0 ] = arr [ 0 ] [ 0 ] [ 0 ] ; for ( i = 1 ; i < l ; i ++ ) tSum [ i ] [ 0 ] [ 0 ] = tSum [ i - 1 ] [ 0 ] [ 0 ] + arr [ i ] [ 0 ] [ 0 ] ; for ( j = 1 ; j < m ; j ++ ) tSum [ 0 ] [ j ] [ 0 ] = tSum [ 0 ] [ j - 1 ] [ 0 ] + arr [ 0 ] [ j ] [ 0 ] ; for ( k = 1 ; k < n ; k ++ ) tSum [ 0 ] [ 0 ] [ k ] = tSum [ 0 ] [ 0 ] [ k - 1 ] + arr [ 0 ] [ 0 ] [ k ] ; for ( i = 1 ; i < l ; i ++ ) for ( j = 1 ; j < m ; j ++ ) tSum [ i ] [ j ] [ 0 ] = min ( tSum [ i - 1 ] [ j ] [ 0 ] , tSum [ i ] [ j - 1 ] [ 0 ] , INT_MAX ) + arr [ i ] [ j ] [ 0 ] ; for ( i = 1 ; i < l ; i ++ ) for ( k = 1 ; k < n ; k ++ ) tSum [ i ] [ 0 ] [ k ] = min ( tSum [ i - 1 ] [ 0 ] [ k ] , tSum [ i ] [ 0 ] [ k - 1 ] , INT_MAX ) + arr [ i ] [ 0 ] [ k ] ; for ( k = 1 ; k < n ; k ++ ) for ( j = 1 ; j < m ; j ++ ) tSum [ 0 ] [ j ] [ k ] = min ( tSum [ 0 ] [ j ] [ k - 1 ] , tSum [ 0 ] [ j - 1 ] [ k ] , INT_MAX ) + arr [ 0 ] [ j ] [ k ] ; for ( i = 1 ; i < l ; i ++ ) for ( j = 1 ; j < m ; j ++ ) for ( k = 1 ; k < n ; k ++ ) tSum [ i ] [ j ] [ k ] = min ( tSum [ i - 1 ] [ j ] [ k ] , tSum [ i ] [ j - 1 ] [ k ] , tSum [ i ] [ j ] [ k - 1 ] ) + arr [ i ] [ j ] [ k ] ; return tSum [ l - 1 ] [ m - 1 ] [ n - 1 ] ; } int main ( ) { int arr [ l ] [ m ] [ n ] = { { { 1 , 2 , 4 } , { 3 , 4 , 5 } , { 5 , 2 , 1 } } , { { 4 , 8 , 3 } , { 5 , 2 , 1 } , { 3 , 4 , 2 } } , { { 2 , 4 , 1 } , { 3 , 1 , 4 } , { 6 , 3 , 8 } } } ; cout << minPathSum ( arr ) ; return 0 ; }

Index/key variables: i, j, k, l, m, n
Accumulator variables: i, j, k, stdc
Iterator variables: i, j, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printParenthesis ( int i , int j , int n , int * bracket , char & name ) { if ( i == j ) { cout << name ++ ; return ; } cout << " ( " ; printParenthesis ( i , * ( ( bracket + i * n ) + j ) , n , bracket , name ) ; printParenthesis ( * ( ( bracket + i * n ) + j ) + 1 , j , n , bracket , name ) ; cout << " ) " ; } void matrixChainOrder ( int p [ ] , int n ) { int m [ n ] [ n ] ; int bracket [ n ] [ n ] ; for ( int i = 1 ; i < n ; i ++ ) m [ i ] [ i ] = 0 ; for ( int L = 2 ; L < n ; L ++ ) { for ( int i = 1 ; i < n - L + 1 ; i ++ ) { int j = i + L - 1 ; m [ i ] [ j ] = INT_MAX ; for ( int k = i ; k <= j - 1 ; k ++ ) { int q = m [ i ] [ k ] + m [ k + 1 ] [ j ] + p [ i - 1 ] * p [ k ] * p [ j ] ; if ( q < m [ i ] [ j ] ) { m [ i ] [ j ] = q ; bracket [ i ] [ j ] = k ; } } } } char name = ' A ' ; cout << " Optimal ▁ Parenthesization ▁ is ▁ : ▁ " ; printParenthesis ( 1 , n - 1 , n , ( int * ) bracket , name ) ; cout << " nOptimal ▁ Cost ▁ is ▁ : ▁ " << m [ 1 ] [ n - 1 ] ; } int main ( ) { int arr [ ] = { 40 , 20 , 30 , 10 , 30 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; matrixChainOrder ( arr , n ) ; return 0 ; }

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

Index/key variables: N, i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; long long int MaxDotProduct ( int A [ ] , int B [ ] , int m , int n ) { long long int dp [ n + 1 ] [ m + 1 ] ; memset ( dp , 0 , sizeof ( dp ) ) ; for ( int i = 1 ; i <= n ; i ++ ) for ( int j = i ; j <= m ; j ++ ) dp [ i ] [ j ] = max ( ( dp [ i - 1 ] [ j - 1 ] + ( A [ j - 1 ] * B [ i - 1 ] ) ) , dp [ i ] [ j - 1 ] ) ; return dp [ n ] [ m ] ; } int main ( ) { int A [ ] = { 2 , 3 , 1 , 7 , 8 } ; int B [ ] = { 3 , 6 , 7 } ; int m = sizeof ( A ) / sizeof ( A [ 0 ] ) ; int n = sizeof ( B ) / sizeof ( B [ 0 ] ) ; cout << MaxDotProduct ( A , B , 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 ; string X = " AGGT12" ; string Y = "12TXAYB " ; string Z = "12XBA " ; int dp [ 100 ] [ 100 ] [ 100 ] ; int lcsOf3 ( int i , int j , int k ) { if ( i == -1 j == -1 k == -1 ) return 0 ; if ( dp [ i ] [ j ] [ k ] != -1 ) return dp [ i ] [ j ] [ k ] ; if ( X [ i ] == Y [ j ] && Y [ j ] == Z [ k ] ) return dp [ i ] [ j ] [ k ] = 1 + lcsOf3 ( i - 1 , j - 1 , k - 1 ) ; else return dp [ i ] [ j ] [ k ] = max ( max ( lcsOf3 ( i - 1 , j , k ) , lcsOf3 ( i , j - 1 , k ) ) , lcsOf3 ( i , j , k - 1 ) ) ; } int main ( ) { memset ( dp , -1 , sizeof ( dp ) ) ; int m = X . length ( ) ; int n = Y . length ( ) ; int o = Z . length ( ) ; cout << " Length ▁ of ▁ LCS ▁ is ▁ " << lcsOf3 ( m - 1 , n - 1 , o - 1 ) ; }

Index/key variables: i, j, k
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
#define MAX  102
using namespace std ; int countMin ( int arr [ ] , int dp [ MAX ] [ MAX ] [ MAX ] , int n , int dec , int inc , int i ) { if ( dp [ dec ] [ inc ] [ i ] != -1 ) return dp [ dec ] [ inc ] [ i ] ; if ( i == n ) return 0 ; if ( arr [ i ] < arr [ dec ] ) dp [ dec ] [ inc ] [ i ] = countMin ( arr , dp , n , i , inc , i + 1 ) ; if ( arr [ i ] > arr [ inc ] ) { if ( dp [ dec ] [ inc ] [ i ] == -1 ) dp [ dec ] [ inc ] [ i ] = countMin ( arr , dp , n , dec , i , i + 1 ) ; else dp [ dec ] [ inc ] [ i ] = min ( countMin ( arr , dp , n , dec , i , i + 1 ) , dp [ dec ] [ inc ] [ i ] ) ; } if ( dp [ dec ] [ inc ] [ i ] == -1 ) dp [ dec ] [ inc ] [ i ] = 1 + countMin ( arr , dp , n , dec , inc , i + 1 ) ; else dp [ dec ] [ inc ] [ i ] = min ( 1 + countMin ( arr , dp , n , dec , inc , i + 1 ) , dp [ dec ] [ inc ] [ i ] ) ; return dp [ dec ] [ inc ] [ i ] ; } int wrapper ( int arr [ ] , int n ) { arr [ MAX - 2 ] = INT_MAX ; arr [ MAX - 1 ] = INT_MIN ; int dp [ MAX ] [ MAX ] [ MAX ] ; memset ( dp , -1 , sizeof dp ) ; return countMin ( arr , dp , n , MAX - 2 , MAX - 1 , 0 ) ; } int main ( ) { int n = 12 ; int arr [ MAX ] = { 7 , 8 , 1 , 2 , 4 , 6 , 3 , 5 , 2 , 1 , 8 , 7 } ; cout << wrapper ( arr , n ) << endl ; return 0 ; }

Index/key variables: MAX, dec, i, inc
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void distSumRec ( int arr [ ] , int n , int sum , int currindex , unordered_set < int > & s ) { if ( currindex > n ) return ; if ( currindex == n ) { s . insert ( sum ) ; return ; } distSumRec ( arr , n , sum + arr [ currindex ] , currindex + 1 , s ) ; distSumRec ( arr , n , sum , currindex + 1 , s ) ; } void printDistSum ( int arr [ ] , int n ) { unordered_set < int > s ; distSumRec ( arr , n , 0 , 0 , s ) ; for ( auto i = s . begin ( ) ; i != s . end ( ) ; i ++ ) cout << * i << " ▁ " ; } int main ( ) { int arr [ ] = { 2 , 3 , 4 , 5 , 6 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; printDistSum ( arr , n ) ; return 0 ; }

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

Index/key variables: i, j, n
Accumulator variables: i, j, stdc, sum
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int ugly ( int a [ ] , int size , int n ) { if ( n <= 0 ) return -1 ; if ( n == 1 ) return 1 ; priority_queue < int , vector < int > , greater < int > > pq ; for ( int i = 0 ; i < size ; i ++ ) { pq . push ( a [ i ] ) ; } int count = 1 , no ; while ( count < n ) { no = pq . top ( ) ; pq . pop ( ) ; if ( no != pq . top ( ) ) { count ++ ; for ( int i = 0 ; i < size ; i ++ ) { pq . push ( no * a [ i ] ) ; } } } return no ; } int main ( ) { int a [ 3 ] = { 2 , 3 , 5 } ; int size = sizeof ( a ) / sizeof ( a [ 0 ] ) ; cout << ugly ( a , size , 10 ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define R  4
#define C  4
int countPaths ( int maze [ ] [ C ] ) { if ( maze [ 0 ] [ 0 ] == -1 ) return 0 ; for ( int i = 0 ; i < R ; i ++ ) { if ( maze [ i ] [ 0 ] == 0 ) maze [ i ] [ 0 ] = 1 ; else break ; } for ( int i = 1 ; i < C ; i ++ ) { if ( maze [ 0 ] [ i ] == 0 ) maze [ 0 ] [ i ] = 1 ; else break ; } for ( int i = 1 ; i < R ; i ++ ) { for ( int j = 1 ; j < C ; j ++ ) { if ( maze [ i ] [ j ] == -1 ) continue ; if ( maze [ i - 1 ] [ j ] > 0 ) maze [ i ] [ j ] = ( maze [ i ] [ j ] + maze [ i - 1 ] [ j ] ) ; if ( maze [ i ] [ j - 1 ] > 0 ) maze [ i ] [ j ] = ( maze [ i ] [ j ] + maze [ i ] [ j - 1 ] ) ; } } return ( maze [ R - 1 ] [ C - 1 ] > 0 ) ? maze [ R - 1 ] [ C - 1 ] : 0 ; } int main ( ) { int maze [ R ] [ C ] = { { 0 , 0 , 0 , 0 } , { 0 , -1 , 0 , 0 } , { -1 , 0 , 0 , 0 } , { 0 , 0 , 0 , 0 } } ; cout << countPaths ( maze ) ; return 0 ; }

Index/key variables: C, R, i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <iostream>
using namespace std ; int minSum ( int arr [ ] , int n ) { int dp [ n ] ; if ( n == 1 ) return arr [ 0 ] ; if ( n == 2 ) return min ( arr [ 0 ] , arr [ 1 ] ) ; if ( n == 3 ) return min ( arr [ 0 ] , min ( arr [ 1 ] , arr [ 2 ] ) ) ; if ( n == 4 ) return min ( min ( arr [ 0 ] , arr [ 1 ] ) , min ( arr [ 2 ] , arr [ 3 ] ) ) ; dp [ 0 ] = arr [ 0 ] ; dp [ 1 ] = arr [ 1 ] ; dp [ 2 ] = arr [ 2 ] ; dp [ 3 ] = arr [ 3 ] ; for ( int i = 4 ; i < n ; i ++ ) dp [ i ] = arr [ i ] + min ( min ( dp [ i - 1 ] , dp [ i - 2 ] ) , min ( dp [ i - 3 ] , dp [ i - 4 ] ) ) ; return min ( min ( dp [ n - 1 ] , dp [ n - 2 ] ) , min ( dp [ n - 4 ] , dp [ n - 3 ] ) ) ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 3 , 4 , 5 , 6 , 1 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << minSum ( arr , n ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define N  4
long long int maxDecimalValue ( int mat [ ] [ N ] , int i , int j , int p ) { if ( i >= N j >= N ) return 0 ; int result = max ( maxDecimalValue ( mat , i , j + 1 , p + 1 ) , maxDecimalValue ( mat , i + 1 , j , p + 1 ) ) ; if ( mat [ i ] [ j ] == 1 ) return pow ( 2 , p ) + result ; else return result ; } int main ( ) { int mat [ ] [ 4 ] = { { 1 , 1 , 0 , 1 } , { 0 , 1 , 1 , 0 } , { 1 , 0 , 0 , 1 } , { 1 , 0 , 1 , 1 } , } ; cout << maxDecimalValue ( mat , 0 , 0 , 0 ) << endl ; return 0 ; }

Index/key variables: N, i, j
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define N  4
long long int MaximumDecimalValue ( int mat [ ] [ N ] , int n ) { int dp [ n ] [ n ] ; memset ( dp , 0 , sizeof ( dp ) ) ; if ( mat [ 0 ] [ 0 ] == 1 ) for ( int i = 1 ; i < n ; i ++ ) { if ( mat [ 0 ] [ i ] == 1 ) dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + pow ( 2 , i ) ; else dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] ; } for ( int i = 1 ; i < n ; i ++ ) { if ( mat [ i ] [ 0 ] == 1 ) dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] + pow ( 2 , i ) ; else dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] ; } for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 1 ; j < n ; j ++ ) { if ( mat [ i ] [ j ] == 1 ) dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) + pow ( 2 , i + j ) ; else dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ; } } return dp [ n - 1 ] [ n - 1 ] ; } int main ( ) { int mat [ ] [ 4 ] = { { 1 , 1 , 0 , 1 } , { 0 , 1 , 1 , 0 } , { 1 , 0 , 0 , 1 } , { 1 , 0 , 1 , 1 } , } ; cout << MaximumDecimalValue ( mat , 4 ) << endl ; return 0 ; }

Index/key variables: N, i, j, n
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int CountPS ( char str [ ] , int n ) { int dp [ n ] [ n ] ; memset ( dp , 0 , sizeof ( dp ) ) ; bool P [ n ] [ n ] ; memset ( P , false , sizeof ( P ) ) ; for ( int i = 0 ; i < n ; i ++ ) P [ i ] [ i ] = true ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( str [ i ] == str [ i + 1 ] ) { P [ i ] [ i + 1 ] = true ; dp [ i ] [ i + 1 ] = 1 ; } } for ( int gap = 2 ; gap < n ; gap ++ ) { for ( int i = 0 ; i < n - gap ; i ++ ) { int j = gap + i ; if ( str [ i ] == str [ j ] && P [ i + 1 ] [ j - 1 ] ) P [ i ] [ j ] = true ; if ( P [ i ] [ j ] == true ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] + 1 - dp [ i + 1 ] [ j - 1 ] ; else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] - dp [ i + 1 ] [ j - 1 ] ; } } return dp [ 0 ] [ n - 1 ] ; } int main ( ) { char str [ ] = " abaab " ; int n = strlen ( str ) ; cout << CountPS ( str , n ) << endl ; return 0 ; }

Index/key variables: i, j, n
Accumulator variables: gap, i, stdc
Iterator variables: gap, i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxSumWO3Consec ( int arr [ ] , int n ) { int sum [ n ] ; if ( n >= 1 ) sum [ 0 ] = arr [ 0 ] ; if ( n >= 2 ) sum [ 1 ] = arr [ 0 ] + arr [ 1 ] ; if ( n > 2 ) sum [ 2 ] = max ( sum [ 1 ] , max ( arr [ 1 ] + arr [ 2 ] , arr [ 0 ] + arr [ 2 ] ) ) ; for ( int i = 3 ; i < n ; i ++ ) sum [ i ] = max ( max ( sum [ i - 1 ] , sum [ i - 2 ] + arr [ i ] ) , arr [ i ] + arr [ i - 1 ] + sum [ i - 3 ] ) ; return sum [ n - 1 ] ; } int main ( ) { int arr [ ] = { 100 , 1000 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << maxSumWO3Consec ( arr , 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 maxSumPairWithDifferenceLessThanK ( int arr [ ] , int N , int K ) { sort ( arr , arr + N ) ; int dp [ N ] ; dp [ 0 ] = 0 ; for ( int i = 1 ; i < N ; i ++ ) { dp [ i ] = dp [ i - 1 ] ; if ( arr [ i ] - arr [ i - 1 ] < K ) { if ( i >= 2 ) dp [ i ] = max ( dp [ i ] , dp [ i - 2 ] + arr [ i ] + arr [ i - 1 ] ) ; else dp [ i ] = max ( dp [ i ] , arr [ i ] + arr [ i - 1 ] ) ; } } return dp [ N - 1 ] ; } int main ( ) { int arr [ ] = { 3 , 5 , 10 , 15 , 17 , 12 , 9 } ; int N = sizeof ( arr ) / sizeof ( int ) ; int K = 4 ; cout << maxSumPairWithDifferenceLessThanK ( arr , N , K ) ; return 0 ; }

Index/key variables: N, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int breakSum ( int n ) { if ( n == 0 n == 1 ) return n ; return max ( ( breakSum ( n / 2 ) + breakSum ( n / 3 ) + breakSum ( n / 4 ) ) , n ) ; } int main ( ) { int n = 12 ; cout << breakSum ( n ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <cstring>
#include <iostream>
using namespace std ; int countPS ( string str ) { int N = str . length ( ) ; int cps [ N + 1 ] [ N + 1 ] ; memset ( cps , 0 , sizeof ( cps ) ) ; for ( int i = 0 ; i < N ; i ++ ) cps [ i ] [ i ] = 1 ; for ( int L = 2 ; L <= N ; L ++ ) { for ( int i = 0 ; i <= N - L ; i ++ ) { int k = L + i - 1 ; if ( str [ i ] == str [ k ] ) cps [ i ] [ k ] = cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] + 1 ; else cps [ i ] [ k ] = cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] - cps [ i + 1 ] [ k - 1 ] ; } } return cps [ 0 ] [ N - 1 ] ; } int main ( ) { string str = " abcb " ; cout << " Total ▁ palindromic ▁ subsequence ▁ are ▁ : ▁ " << countPS ( str ) << endl ; return 0 ; }

Index/key variables: i, k
Accumulator variables: L, i
Iterator variables: L, i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int n , dp [ 1000 ] [ 1000 ] ; string str = " abcb " ; int countPS ( int i , int j ) { if ( i > j ) return 0 ; if ( dp [ i ] [ j ] != -1 ) return dp [ i ] [ j ] ; if ( i == j ) return dp [ i ] [ j ] = 1 ; else if ( str [ i ] == str [ j ] ) return dp [ i ] [ j ] = countPS ( i + 1 , j ) + countPS ( i , j - 1 ) + 1 ; else return dp [ i ] [ j ] = countPS ( i + 1 , j ) + countPS ( i , j - 1 ) - countPS ( i + 1 , j - 1 ) ; } int main ( ) { memset ( dp , -1 , sizeof ( dp ) ) ; n = str . size ( ) ; cout << " Total ▁ palindromic ▁ subsequence ▁ are ▁ : ▁ " << countPS ( 0 , n - 1 ) << endl ; return 0 ; }

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