dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool * * dp ; void display ( const vector < int > & v ) { for ( int i = 0 ; i < v . size ( ) ; ++ i ) printf ( " % d ▁ " , v [ i ] ) ; printf ( " STRNEWLINE " ) ; } void printSubsetsRec ( int arr [ ] , int i , int sum , vector < int > & p ) { if ( i == 0 && sum != 0 && dp [ 0 ] [ sum ] ) { p . push_back ( arr [ i ] ) ; if ( arr [ i ] == sum ) display ( p ) ; return ; } if ( i == 0 && sum == 0 ) { display ( p ) ; return ; } if ( dp [ i - 1 ] [ sum ] ) { vector < int > b = p ; printSubsetsRec ( arr , i - 1 , sum , b ) ; } if ( sum >= arr [ i ] && dp [ i - 1 ] [ sum - arr [ i ] ] ) { p . push_back ( arr [ i ] ) ; printSubsetsRec ( arr , i - 1 , sum - arr [ i ] , p ) ; } } void printAllSubsets ( int arr [ ] , int n , int sum ) { if ( n == 0 sum < 0 ) return ; dp = new bool * [ n ] ; for ( int i = 0 ; i < n ; ++ i ) { dp [ i ] = new bool [ sum + 1 ] ; dp [ i ] [ 0 ] = true ; } if ( arr [ 0 ] <= sum ) dp [ 0 ] [ arr [ 0 ] ] = true ; for ( int i = 1 ; i < n ; ++ i ) for ( int j = 0 ; j < sum + 1 ; ++ j ) dp [ i ] [ j ] = ( arr [ i ] <= j ) ? dp [ i - 1 ] [ j ] || dp [ i - 1 ] [ j - arr [ i ] ] : dp [ i - 1 ] [ j ] ; if ( dp [ n - 1 ] [ sum ] == false ) { printf ( " There ▁ are ▁ no ▁ subsets ▁ with ▁ sum ▁ % d STRNEWLINE " , sum ) ; return ; } vector < int > p ; printSubsetsRec ( arr , n - 1 , sum , p ) ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int sum = 10 ; printAllSubsets ( arr , n , sum ) ; return 0 ; }

Index/key variables: i, j, n, sum
Accumulator variables: stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define M  26
int toInt ( char ch ) { return ( ch - ' a ' ) ; } int waysToIncreaseLCSBy1 ( string str1 , string str2 ) { int m = str1 . length ( ) , n = str2 . length ( ) ; vector < int > position [ M ] ; for ( int i = 1 ; i <= n ; i ++ ) position [ toInt ( str2 [ i - 1 ] ) ] . push_back ( i ) ; int lcsl [ m + 2 ] [ n + 2 ] ; int lcsr [ m + 2 ] [ n + 2 ] ; for ( int i = 0 ; i <= m + 1 ; i ++ ) for ( int j = 0 ; j <= n + 1 ; j ++ ) lcsl [ i ] [ j ] = lcsr [ i ] [ j ] = 0 ; for ( int i = 1 ; i <= m ; i ++ ) { for ( int j = 1 ; j <= n ; j ++ ) { if ( str1 [ i - 1 ] == str2 [ j - 1 ] ) lcsl [ i ] [ j ] = 1 + lcsl [ i - 1 ] [ j - 1 ] ; else lcsl [ i ] [ j ] = max ( lcsl [ i - 1 ] [ j ] , lcsl [ i ] [ j - 1 ] ) ; } } for ( int i = m ; i >= 1 ; i -- ) { for ( int j = n ; j >= 1 ; j -- ) { if ( str1 [ i - 1 ] == str2 [ j - 1 ] ) lcsr [ i ] [ j ] = 1 + lcsr [ i + 1 ] [ j + 1 ] ; else lcsr [ i ] [ j ] = max ( lcsr [ i + 1 ] [ j ] , lcsr [ i ] [ j + 1 ] ) ; } } int ways = 0 ; for ( int i = 0 ; i <= m ; i ++ ) { for ( char c = ' a ' ; c <= ' z ' ; c ++ ) { for ( int j = 0 ; j < position [ toInt ( c ) ] . size ( ) ; j ++ ) { int p = position [ toInt ( c ) ] [ j ] ; if ( lcsl [ i ] [ p - 1 ] + lcsr [ i + 1 ] [ p + 1 ] == lcsl [ m ] [ n ] ) ways ++ ; } } } return ways ; } int main ( ) { string str1 = " abcabc " ; string str2 = " abcd " ; cout << waysToIncreaseLCSBy1 ( str1 , str2 ) ; return 0 ; }

Index/key variables: M, i, j, m, n
Accumulator variables: c, i, j, stdc, ways
Iterator variables: c, i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countStr ( int n , int bCount , int cCount ) { if ( bCount < 0 cCount < 0 ) return 0 ; if ( n == 0 ) return 1 ; if ( bCount == 0 && cCount == 0 ) return 1 ; int res = countStr ( n - 1 , bCount , cCount ) ; res += countStr ( n - 1 , bCount - 1 , cCount ) ; res += countStr ( n - 1 , bCount , cCount - 1 ) ; return res ; } int main ( ) { int n = 3 ; cout << countStr ( n , 1 , 2 ) ; return 0 ; }

Accumulator variables: res, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define N  4
int MaximumPath ( int Mat [ ] [ N ] ) { int result = 0 ; int dp [ N ] [ N + 2 ] ; memset ( dp , 0 , sizeof ( dp ) ) ; for ( int i = 0 ; i < N ; i ++ ) dp [ 0 ] [ i + 1 ] = Mat [ 0 ] [ i ] ; for ( int i = 1 ; i < N ; i ++ ) for ( int j = 1 ; j <= N ; j ++ ) dp [ i ] [ j ] = max ( dp [ i - 1 ] [ j - 1 ] , max ( dp [ i - 1 ] [ j ] , dp [ i - 1 ] [ j + 1 ] ) ) + Mat [ i ] [ j - 1 ] ; for ( int i = 0 ; i <= N ; i ++ ) result = max ( result , dp [ N - 1 ] [ i ] ) ; return result ; } int main ( ) { int Mat [ 4 ] [ 4 ] = { { 4 , 2 , 3 , 4 } , { 2 , 9 , 1 , 10 } , { 15 , 1 , 3 , 0 } , { 16 , 92 , 41 , 44 } } ; cout << MaximumPath ( Mat ) << endl ; 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 ; #define MAX  100001
double dp [ MAX ] ; double probability ( int k , int n ) { double ans = 0 ; for ( int i = k ; i <= n ; ++ i ) { double res = dp [ n ] - dp [ i ] - dp [ n - i ] - n ; ans += pow ( 2.0 , res ) ; } return ans ; } void precompute ( ) { for ( int i = 2 ; i < MAX ; ++ i ) dp [ i ] = log2 ( i ) + dp [ i - 1 ] ; } int main ( ) { precompute ( ) ; cout << probability ( 2 , 3 ) << " STRNEWLINE " ; cout << probability ( 3 , 6 ) << " STRNEWLINE " ; cout << probability ( 500 , 1000 ) ; return 0 ; }

Index/key variables: MAX, i, n
Accumulator variables: ans, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool canVote ( int a [ ] , int n , int x ) { int dp [ n + 1 ] [ x + 1 ] ; memset ( dp , 0 , sizeof ( dp ) ) ; int sum = 0 ; for ( int i = 0 ; i <= n ; i ++ ) sum += a [ i ] ; for ( int i = 1 ; i <= n ; i ++ ) for ( int j = 1 ; j <= x ; j ++ ) if ( a [ i ] <= j ) dp [ i ] [ j ] = max ( dp [ i - 1 ] [ j ] , a [ i ] + dp [ i - 1 ] [ j - a [ i ] ] ) ; else dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ; return ( sum - dp [ n ] [ x ] <= x ) ; } int main ( ) { int n = 3 , x = 4 ; int a [ ] = { 2 , 4 , 2 } ; canVote ( a , n , x ) ? cout << " YES STRNEWLINE " : cout << " NO STRNEWLINE " ; return 0 ; }

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

Index/key variables: i, n
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
typedef long long ll ; using namespace std ; int minSum ( int ar [ ] , int n ) { if ( n <= 4 ) return * min_element ( ar , ar + n ) ; int sum [ n ] ; sum [ 0 ] = ar [ 0 ] ; sum [ 1 ] = ar [ 1 ] ; sum [ 2 ] = ar [ 2 ] ; sum [ 3 ] = ar [ 3 ] ; for ( int i = 4 ; i < n ; i ++ ) sum [ i ] = ar [ i ] + ( * min_element ( sum + i - 4 , sum + i ) ) ; return * min_element ( sum + n - 4 , sum + n ) ; } int main ( ) { int ar [ ] = { 2 , 4 , 1 , 5 , 2 , 3 , 6 , 1 , 2 , 4 } ; int n = sizeof ( ar ) / sizeof ( ar [ 0 ] ) ; cout << " Minimum ▁ sum ▁ = ▁ " << minSum ( ar , 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 maxAlternateSum ( int arr [ ] , int n ) { if ( n == 1 ) return arr [ 0 ] ; int min = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { if ( min > arr [ i ] ) min = arr [ i ] ; } if ( min == arr [ 0 ] ) { return arr [ 0 ] ; } int dec [ n ] ; memset ( dec , 0 , sizeof ( dec ) ) ; int inc [ n ] ; memset ( inc , 0 , sizeof ( inc ) ) ; dec [ 0 ] = inc [ 0 ] = arr [ 0 ] ; int flag = 0 ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 0 ; j < i ; j ++ ) { if ( arr [ j ] > arr [ i ] ) { dec [ i ] = max ( dec [ i ] , inc [ j ] + arr [ i ] ) ; flag = 1 ; } else if ( arr [ j ] < arr [ i ] && flag == 1 ) inc [ i ] = max ( inc [ i ] , dec [ j ] + arr [ i ] ) ; } } int result = INT_MIN ; for ( int i = 0 ; i < n ; i ++ ) { if ( result < inc [ i ] ) result = inc [ i ] ; if ( result < dec [ i ] ) result = dec [ i ] ; } return result ; } int main ( ) { int arr [ ] = { 8 , 2 , 3 , 5 , 7 , 9 , 10 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << " Maximum ▁ sum ▁ = ▁ " << maxAlternateSum ( arr , n ) << endl ; return 0 ; }

Index/key variables: i, j, n
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <iostream>
using namespace std ; int pad ( int n ) { int pPrevPrev = 1 , pPrev = 1 , pCurr = 1 , pNext = 1 ; for ( int i = 3 ; i <= n ; i ++ ) { pNext = pPrevPrev + pPrev ; pPrevPrev = pPrev ; pPrev = pCurr ; pCurr = pNext ; } return pNext ; } int main ( ) { int n = 12 ; cout << pad ( n ) ; return 0 ; }

Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define ROW  4
#define COL  5
int isSafe ( int M [ ] [ COL ] , int row , int col , bool visited [ ] [ COL ] ) { return ( row >= 0 ) && ( row < ROW ) && ( col >= 0 ) && ( col < COL ) && ( M [ row ] [ col ] && ! visited [ row ] [ col ] ) ; } void DFS ( int M [ ] [ COL ] , int row , int col , bool visited [ ] [ COL ] , int & count ) { static int rowNbr [ ] = { -1 , -1 , -1 , 0 , 0 , 1 , 1 , 1 } ; static int colNbr [ ] = { -1 , 0 , 1 , -1 , 1 , -1 , 0 , 1 } ; visited [ row ] [ col ] = true ; for ( int k = 0 ; k < 8 ; ++ k ) { if ( isSafe ( M , row + rowNbr [ k ] , col + colNbr [ k ] , visited ) ) { count ++ ; DFS ( M , row + rowNbr [ k ] , col + colNbr [ k ] , visited , count ) ; } } } int largestRegion ( int M [ ] [ COL ] ) { bool visited [ ROW ] [ COL ] ; memset ( visited , 0 , sizeof ( visited ) ) ; int result = INT_MIN ; for ( int i = 0 ; i < ROW ; ++ i ) { for ( int j = 0 ; j < COL ; ++ j ) { if ( M [ i ] [ j ] && ! visited [ i ] [ j ] ) { int count = 1 ; DFS ( M , i , j , visited , count ) ; result = max ( result , count ) ; } } } return result ; } int main ( ) { int M [ ] [ COL ] = { { 0 , 0 , 1 , 1 , 0 } , { 1 , 0 , 1 , 1 , 0 } , { 0 , 1 , 0 , 0 , 0 } , { 0 , 0 , 0 , 0 , 1 } } ; cout << largestRegion ( M ) ; return 0 ; }

Index/key variables: COL, ROW, col, i, j, k, row
Accumulator variables: count, stdc
Iterator variables: i, j, k
C++ program:
#include <stdio.h>
int lucas ( int n ) { int a = 2 , b = 1 , c , i ; if ( n == 0 ) return a ; for ( i = 2 ; i <= n ; i ++ ) { c = a + b ; a = b ; b = c ; } return b ; } int main ( ) { int n = 9 ; printf ( " % d " , lucas ( n ) ) ; return 0 ; }

Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
#define MAX  1000000
using namespace std ; int breakSum ( int n ) { int dp [ n + 1 ] ; dp [ 0 ] = 0 , dp [ 1 ] = 1 ; for ( int i = 2 ; i <= n ; i ++ ) dp [ i ] = max ( dp [ i / 2 ] + dp [ i / 3 ] + dp [ i / 4 ] , i ) ; return dp [ n ] ; } int main ( ) { int n = 24 ; cout << breakSum ( n ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string longestRepeatedSubstring ( string str ) { int n = str . length ( ) ; int LCSRe [ n + 1 ] [ n + 1 ] ; memset ( LCSRe , 0 , sizeof ( LCSRe ) ) ; int i , index = 0 ; for ( i = 1 ; i <= n ; i ++ ) { for ( int j = i + 1 ; j <= n ; j ++ ) { if ( str [ i - 1 ] == str [ j - 1 ] && LCSRe [ i - 1 ] [ j - 1 ] < ( j - i ) ) { LCSRe [ i ] [ j ] = LCSRe [ i - 1 ] [ j - 1 ] + 1 ; if ( LCSRe [ i ] [ j ] > res_length ) { res_length = LCSRe [ i ] [ j ] ; index = max ( i , index ) ; } } else LCSRe [ i ] [ j ] = 0 ; } } if ( res_length > 0 ) for ( i = index - res_length + 1 ; i <= index ; i ++ ) res . push_back ( str [ i - 1 ] ) ; return res ; } int main ( ) { string str = " geeksforgeeks " ; cout << longestRepeatedSubstring ( str ) ; 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 minCost ( int cost [ ] , int n ) { int dp [ n + 1 ] ; dp [ 0 ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { int min_cost = INT_MAX ; for ( int j = 0 ; j < i ; j ++ ) if ( j < n && cost [ j ] != -1 ) min_cost = min ( min_cost , cost [ j ] + dp [ i - j - 1 ] ) ; dp [ i ] = min_cost ; } return dp [ n ] ; } int main ( ) { int cost [ ] = { 20 , 10 , 4 , 50 , 100 } ; int W = sizeof ( cost ) / sizeof ( cost [ 0 ] ) ; cout << minCost ( cost , W ) ; return 0 ; }

Index/key variables: i, j, n
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <iostream>
#include <vector>
using namespace std ; int findSum ( vector < int > arr ) { int sum = 0 ; for ( int i : arr ) sum += i ; return sum ; } void printMaxSumIS ( 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 ] ) && ( findSum ( L [ i ] ) < findSum ( L [ j ] ) ) ) L [ i ] = L [ j ] ; } L [ i ] . push_back ( arr [ i ] ) ; } vector < int > res = L [ 0 ] ; for ( vector < int > x : L ) if ( findSum ( x ) > findSum ( res ) ) res = x ; for ( int i : res ) cout << i << " ▁ " ; cout << endl ; } int main ( ) { int arr [ ] = { 3 , 2 , 6 , 4 , 5 , 1 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; printMaxSumIS ( arr , n ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: i, j, x
C++ program:
#include <iostream>
#include <vector>
using namespace std ; void printLIS ( vector < int > & arr ) { for ( int x : arr ) cout << x << " ▁ " ; cout << endl ; } void constructPrintLIS ( 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 ( ) + 1 ) ) L [ i ] = L [ j ] ; } L [ i ] . push_back ( arr [ i ] ) ; } vector < int > max = L [ 0 ] ; for ( vector < int > x : L ) if ( x . size ( ) > max . size ( ) ) max = x ; printLIS ( max ) ; } int main ( ) { int arr [ ] = { 3 , 2 , 6 , 4 , 5 , 1 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; constructPrintLIS ( arr , n ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j, x
C++ program:
#include <bits/stdc++.h>
using namespace std ; int lcs ( string X , string Y , int m , int n ) { int L [ m + 1 ] [ n + 1 ] ; for ( int i = 0 ; i <= m ; i ++ ) { for ( int j = 0 ; j <= n ; j ++ ) { if ( i == 0 j == 0 ) L [ i ] [ j ] = 0 ; else if ( X [ i - 1 ] == Y [ j - 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 ] ; } bool isKPal ( string str , int k ) { int n = str . length ( ) ; string revStr = str ; reverse ( revStr . begin ( ) , revStr . end ( ) ) ; int lps = lcs ( str , revStr , n , n ) ; return ( n - lps <= k ) ; } int main ( ) { string str = " abcdeca " ; int k = 2 ; isKPal ( str , k ) ? cout << " Yes " : cout << " No " ; 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 strmatch ( char str [ ] , char pattern [ ] , int n , int m ) { if ( m == 0 ) return ( n == 0 ) ; bool lookup [ n + 1 ] [ m + 1 ] ; memset ( lookup , false , sizeof ( lookup ) ) ; lookup [ 0 ] [ 0 ] = true ; for ( int j = 1 ; j <= m ; j ++ ) if ( pattern [ j - 1 ] == ' * ' ) lookup [ 0 ] [ j ] = lookup [ 0 ] [ j - 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= m ; j ++ ) { if ( pattern [ j - 1 ] == ' * ' ) lookup [ i ] [ j ] = lookup [ i ] [ j - 1 ] || lookup [ i - 1 ] [ j ] ; else if ( pattern [ j - 1 ] == ' ? ' str [ i - 1 ] == pattern [ j - 1 ] ) lookup [ i ] [ j ] = lookup [ i - 1 ] [ j - 1 ] ; else lookup [ i ] [ j ] = false ; } } return lookup [ n ] [ m ] ; } int main ( ) { char str [ ] = " baaabab " ; char pattern [ ] = " * * * * * ba * * * * * ab " ; if ( strmatch ( str , pattern , strlen ( str ) , strlen ( pattern ) ) ) cout << " Yes " << endl ; else cout << " No " << endl ; 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 isKPalRec ( string str1 , string str2 , int m , int n ) { if ( m == 0 ) return n ; if ( n == 0 ) return m ; if ( str1 [ m - 1 ] == str2 [ n - 1 ] ) return isKPalRec ( str1 , str2 , m - 1 , n - 1 ) ; } bool isKPal ( string str , int k ) { string revStr = str ; reverse ( revStr . begin ( ) , revStr . end ( ) ) ; int len = str . length ( ) ; return ( isKPalRec ( str , revStr , len , len ) <= k * 2 ) ; } int main ( ) { string str = " acdcb " ; int k = 2 ; isKPal ( str , k ) ? cout << " Yes " : cout << " No " ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minTime ( int arr [ ] , int n ) { if ( n <= 0 ) return 0 ; int incl = arr [ 0 ] ; int excl = 0 ; for ( int i = 1 ; i < n ; i ++ ) { int incl_new = arr [ i ] + min ( excl , incl ) ; int excl_new = incl ; incl = incl_new ; excl = excl_new ; } return min ( incl , excl ) ; } int main ( ) { int arr1 [ ] = { 10 , 5 , 2 , 7 , 10 } ; int n1 = sizeof ( arr1 ) / sizeof ( arr1 [ 0 ] ) ; cout << minTime ( arr1 , n1 ) << endl ; int arr2 [ ] = { 10 , 5 , 7 , 10 } ; int n2 = sizeof ( arr2 ) / sizeof ( arr2 [ 0 ] ) ; cout << minTime ( arr2 , n2 ) << endl ; int arr3 [ ] = { 10 , 5 , 2 , 4 , 8 , 6 , 7 , 10 } ; int n3 = sizeof ( arr3 ) / sizeof ( arr3 [ 0 ] ) ; cout << minTime ( arr3 , n3 ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
int lcs ( string & X , string & Y ) { int m = X . length ( ) , n = Y . length ( ) ; int L [ m + 1 ] [ n + 1 ] ; for ( int i = 0 ; i <= m ; i ++ ) { for ( int j = 0 ; j <= n ; j ++ ) { if ( i == 0 j == 0 ) L [ i ] [ j ] = 0 ; else if ( X [ i - 1 ] == Y [ j - 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 ] ; }

Index/key variables: i, j, m, n
Accumulator variables: i, j
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void multiply ( int a [ 3 ] [ 3 ] , int b [ 3 ] [ 3 ] ) { int mul [ 3 ] [ 3 ] ; for ( int i = 0 ; i < 3 ; i ++ ) { for ( int j = 0 ; j < 3 ; j ++ ) { mul [ i ] [ j ] = 0 ; for ( int k = 0 ; k < 3 ; k ++ ) mul [ i ] [ j ] += a [ i ] [ k ] * b [ k ] [ j ] ; } } for ( int i = 0 ; i < 3 ; i ++ ) for ( int j = 0 ; j < 3 ; j ++ ) a [ i ] [ j ] = mul [ i ] [ j ] ; } int power ( int F [ 3 ] [ 3 ] , int n ) { int M [ 3 ] [ 3 ] = { { 1 , 1 , 1 } , { 1 , 0 , 0 } , { 0 , 1 , 0 } } ; if ( n == 1 ) return F [ 0 ] [ 0 ] + F [ 0 ] [ 1 ] ; power ( F , n / 2 ) ; multiply ( F , F ) ; if ( n % 2 != 0 ) multiply ( F , M ) ; return F [ 0 ] [ 0 ] + F [ 0 ] [ 1 ] ; } int findNthTerm ( int n ) { int F [ 3 ] [ 3 ] = { { 1 , 1 , 1 } , { 1 , 0 , 0 } , { 0 , 1 , 0 } } ; if ( n == 0 ) return 0 ; if ( n == 1 n == 2 ) return 1 ; return power ( F , n - 2 ) ; } int main ( ) { int n = 5 ; cout << " F ( 5 ) ▁ is ▁ " << findNthTerm ( n ) ; return 0 ; }

Index/key variables: i, j, k
Accumulator variables: i, j, k, stdc
Iterator variables: i, j, k
C++ program:
#include <iostream>
using namespace std ; int count ( int n ) { int dp [ n + 1 ] ; dp [ 0 ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { if ( i >= 1 && i <= 3 ) dp [ i ] = 1 ; else if ( i == 4 ) dp [ i ] = 2 ; else dp [ i ] = dp [ i - 1 ] + dp [ i - 4 ] ; } return dp [ n ] ; } int main ( ) { int n = 5 ; cout << " Count ▁ of ▁ ways ▁ is ▁ " << count ( n ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int nCrModp ( int n , int r , int p ) { if ( r > n - r ) r = n - r ; int C [ r + 1 ] ; memset ( C , 0 , sizeof ( C ) ) ; C [ 0 ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = min ( i , r ) ; j > 0 ; j -- ) C [ j ] = ( C [ j ] + C [ j - 1 ] ) % p ; } return C [ r ] ; } int main ( ) { int n = 10 , r = 2 , p = 13 ; cout << " Value ▁ of ▁ nCr ▁ % ▁ p ▁ is ▁ " << nCrModp ( n , r , p ) ; return 0 ; }

Index/key variables: j, r
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <iostream>
using namespace std ; int countDer ( int n ) { if ( n == 1 or n == 2 ) { return n - 1 ; } int a = 0 ; int b = 1 ; for ( int i = 3 ; i <= n ; ++ i ) { int cur = ( i - 1 ) * ( a + b ) ; a = b ; b = cur ; } return b ; } int main ( ) { cout << " Count ▁ of ▁ Dearrangements ▁ is ▁ " << countDer ( 4 ) ; return 0 ; }

Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; int bellNumber ( int n ) { int bell [ n + 1 ] [ n + 1 ] ; bell [ 0 ] [ 0 ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { int bellNumber ( int n ) { int bell [ n + 1 ] [ n + 1 ] ; bell [ 0 ] [ 0 ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { bell [ i ] [ 0 ] = bell [ i - 1 ] [ i - 1 ] ; for ( int j = 1 ; j <= i ; j ++ ) bell [ i ] [ j ] = bell [ i - 1 ] [ j - 1 ] + bell [ i ] [ j - 1 ] ; } return bell [ n ] [ 0 ] ; } int main ( ) { for ( int n = 0 ; n <= 5 ; n ++ ) cout << " Bell ▁ Number ▁ " << n << " ▁ is ▁ " << bellNumber ( n ) << endl ; return 0 ; }

Index/key variables: i, j, n
Accumulator variables: i, j, n
Iterator variables: i, j, n
C++ program:
#include <iostream>
using namespace std ; int printCountDP ( int dist ) { int count [ dist + 1 ] ; count [ 0 ] = 1 ; if ( dist >= 1 ) count [ 1 ] = 1 ; if ( dist >= 2 ) count [ 2 ] = 2 ; for ( int i = 3 ; i <= dist ; i ++ ) count [ i ] = count [ i - 1 ] + count [ i - 2 ] + count [ i - 3 ] ; return count [ dist ] ; } int main ( ) { int dist = 4 ; cout << printCountDP ( dist ) ; return 0 ; }

Index/key variables: dist, i
Accumulator variables: i
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; int countSeq ( int n ) { int nCr = 1 , res = 1 ; for ( int r = 1 ; r <= n ; r ++ ) { nCr = ( nCr * ( n + 1 - r ) ) / r ; res += nCr * nCr ; } return res ; } int main ( ) { int n = 2 ; cout << " Count ▁ of ▁ sequences ▁ is ▁ " << countSeq ( n ) ; return 0 ; }

Accumulator variables: r, res
Iterator variables: r
C++ program:
#include <iostream>
using namespace std ; int min ( int a , int b ) { return ( a < b ) ? a : b ; } int min ( int arr [ ] , int l , int h ) { int mn = arr [ l ] ; for ( int i = l + 1 ; i <= h ; i ++ ) if ( mn > arr [ i ] ) mn = arr [ i ] ; return mn ; } int max ( int arr [ ] , int l , int h ) { int mx = arr [ l ] ; for ( int i = l + 1 ; i <= h ; i ++ ) if ( mx < arr [ i ] ) mx = arr [ i ] ; return mx ; } int minRemovalsDP ( int arr [ ] , int n ) { int table [ n ] [ n ] , gap , i , j , mn , mx ; for ( gap = 0 ; gap < n ; ++ gap ) { for ( i = 0 , j = gap ; j < n ; ++ i , ++ j ) { mn = min ( arr , i , j ) ; mx = max ( arr , i , j ) ; table [ i ] [ j ] = ( 2 * mn > mx ) ? 0 : min ( table [ i ] [ j - 1 ] + 1 , table [ i + 1 ] [ j ] + 1 ) ; } } return table [ 0 ] [ n - 1 ] ; } int main ( ) { int arr [ ] = { 20 , 4 , 1 , 3 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << minRemovalsDP ( arr , n ) ; return 0 ; }

Index/key variables: i, j, l, n
Accumulator variables: i
Iterator variables: gap, i
C++ program:
#include <iostream>
using namespace std ; int numberOfPaths ( int m , int n ) { int path = 1 ; for ( int i = n ; i < ( m + n - 1 ) ; i ++ ) { path *= i ; path /= ( i - n + 1 ) ; } return path ; } int main ( ) { cout << numberOfPaths ( 3 , 3 ) ; return 0 ; }

Accumulator variables: i, path
Iterator variables: i