dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . io . * ; class GFG { static int N = 3 ; static int maxPathSum ( int tri [ ] [ ] , 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 ] ; } public static void main ( String [ ] args ) { int tri [ ] [ ] = { { 1 , 0 , 0 } , { 4 , 8 , 0 } , { 1 , 5 , 3 } } ; System . out . println ( maxPathSum ( tri , 2 , 2 ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int MaxDotProduct ( int A [ ] , int B [ ] , int m , int n ) { int dp [ ] [ ] = new int [ n + 1 ] [ m + 1 ] ; for ( int [ ] row : dp ) Arrays . fill ( row , 0 ) ; for ( int i = 1 ; i <= n ; i ++ ) for ( int j = i ; j <= m ; j ++ ) dp [ i ] [ j ] = Math . max ( ( dp [ i - 1 ] [ j - 1 ] + ( A [ j - 1 ] * B [ i - 1 ] ) ) , dp [ i ] [ j - 1 ] ) ; return dp [ n ] [ m ] ; } public static void main ( String [ ] args ) { int A [ ] = { 2 , 3 , 1 , 7 , 8 } ; int B [ ] = { 3 , 6 , 7 } ; int m = A . length ; int n = B . length ; System . out . print ( MaxDotProduct ( A , B , m , n ) ) ; } }

Index/key variables: i, j, m, n
Accumulator variables: i, j
Iterator variables: i, j, row
Class/struct names: GFG
Java program:
class GFG { static String X = " AGGT12" ; static String Y = "12TXAYB " ; static String Z = "12XBA " ; static int [ ] [ ] [ ] dp = new int [ 100 ] [ 100 ] [ 100 ] ; static 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 . charAt ( i ) == Y . charAt ( j ) && Y . charAt ( j ) == Z . charAt ( k ) ) { return dp [ i ] [ j ] [ k ] = 1 + lcsOf3 ( i - 1 , j - 1 , k - 1 ) ; } else { return dp [ i ] [ j ] [ k ] = Math . max ( Math . max ( lcsOf3 ( i - 1 , j , k ) , lcsOf3 ( i , j - 1 , k ) ) , lcsOf3 ( i , j , k - 1 ) ) ; } } public static void main ( String [ ] args ) { for ( int i = 0 ; i < 100 ; i ++ ) { for ( int j = 0 ; j < 100 ; j ++ ) { for ( int k = 0 ; k < 100 ; k ++ ) { dp [ i ] [ j ] [ k ] = - 1 ; } } } int m = X . length ( ) ; int n = Y . length ( ) ; int o = Z . length ( ) ; System . out . print ( " Length ▁ of ▁ LCS ▁ is ▁ " + lcsOf3 ( m - 1 , n - 1 , o - 1 ) ) ; } }

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int MAX = 102 ; static int countMin ( int arr [ ] , int dp [ ] [ ] [ ] , 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 ] = Math . 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 ] = Math . min ( 1 + countMin ( arr , dp , n , dec , inc , i + 1 ) , dp [ dec ] [ inc ] [ i ] ) ; return dp [ dec ] [ inc ] [ i ] ; } static int wrapper ( int arr [ ] , int n ) { arr [ MAX - 2 ] = Integer . MAX_VALUE ; arr [ MAX - 1 ] = Integer . MIN_VALUE ; int [ ] [ ] [ ] dp = new int [ MAX ] [ MAX ] [ MAX ] ; for ( int i = 0 ; i < MAX ; i ++ ) { for ( int j = 0 ; j < MAX ; j ++ ) { for ( int l = 0 ; l < MAX ; l ++ ) dp [ i ] [ j ] [ l ] = - 1 ; } } return countMin ( arr , dp , n , MAX - 2 , MAX - 1 , 0 ) ; } public static void main ( String [ ] args ) { int n = 12 ; int [ ] arr = new int [ MAX ] ; arr [ 0 ] = 7 ; arr [ 1 ] = 8 ; arr [ 2 ] = 1 ; arr [ 3 ] = 2 ; arr [ 4 ] = 4 ; arr [ 5 ] = 6 ; arr [ 6 ] = 3 ; arr [ 7 ] = 5 ; arr [ 8 ] = 2 ; arr [ 9 ] = 1 ; arr [ 10 ] = 8 ; arr [ 11 ] = 7 ; System . out . println ( wrapper ( arr , n ) ) ; } }

Index/key variables: MAX, dec, i, inc, j, l
Accumulator variables: i, j, l
Iterator variables: i, j, l
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static void distSumRec ( int arr [ ] , int n , int sum , int currindex , HashSet < Integer > s ) { if ( currindex > n ) return ; if ( currindex == n ) { s . add ( sum ) ; return ; } distSumRec ( arr , n , sum + arr [ currindex ] , currindex + 1 , s ) ; distSumRec ( arr , n , sum , currindex + 1 , s ) ; } static void printDistSum ( int arr [ ] , int n ) { HashSet < Integer > s = new HashSet < > ( ) ; distSumRec ( arr , n , 0 , 0 , s ) ; for ( int i : s ) System . out . print ( i + " ▁ " ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 3 , 4 , 5 , 6 } ; int n = arr . length ; printDistSum ( arr , n ) ; } }

Index/key variables: currindex
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static void printDistSum ( int arr [ ] , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; boolean [ ] [ ] dp = new boolean [ n + 1 ] [ sum + 1 ] ; 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 ) System . out . print ( j + " ▁ " ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 3 , 4 , 5 , 6 } ; int n = arr . length ; printDistSum ( arr , n ) ; } }

Index/key variables: i, j, n
Accumulator variables: i, j, sum
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int R = 4 ; static int C = 4 ; static int countPaths ( int maze [ ] [ ] ) { 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 ; } public static void main ( String [ ] args ) { int maze [ ] [ ] = { { 0 , 0 , 0 , 0 } , { 0 , - 1 , 0 , 0 } , { - 1 , 0 , 0 , 0 } , { 0 , 0 , 0 , 0 } } ; System . out . println ( countPaths ( maze ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int minSum ( int [ ] arr , int n ) { int [ ] dp = new int [ n ] ; if ( n == 1 ) return arr [ 0 ] ; if ( n == 2 ) return Math . min ( arr [ 0 ] , arr [ 1 ] ) ; if ( n == 3 ) return Math . min ( arr [ 0 ] , Math . min ( arr [ 1 ] , arr [ 2 ] ) ) ; if ( n == 4 ) return Math . min ( Math . min ( arr [ 0 ] , arr [ 1 ] ) , Math . 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 ] + Math . min ( Math . min ( dp [ i - 1 ] , dp [ i - 2 ] ) , Math . min ( dp [ i - 3 ] , dp [ i - 4 ] ) ) ; return Math . min ( Math . min ( dp [ n - 1 ] , dp [ n - 2 ] ) , Math . min ( dp [ n - 4 ] , dp [ n - 3 ] ) ) ; } static public void main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 , 3 , 4 , 5 , 6 , 1 } ; int n = arr . length ; System . out . println ( minSum ( arr , n ) ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static final int N = 4 ; static int maxDecimalValue ( int mat [ ] [ ] , int i , int j , int p ) { if ( i >= N j >= N ) { return 0 ; } int result = Math . max ( maxDecimalValue ( mat , i , j + 1 , p + 1 ) , maxDecimalValue ( mat , i + 1 , j , p + 1 ) ) ; if ( mat [ i ] [ j ] == 1 ) { return ( int ) ( Math . pow ( 2 , p ) + result ) ; } else { return result ; } } public static void main ( String [ ] args ) { int mat [ ] [ ] = { { 1 , 1 , 0 , 1 } , { 0 , 1 , 1 , 0 } , { 1 , 0 , 0 , 1 } , { 1 , 0 , 1 , 1 } , } ; System . out . println ( maxDecimalValue ( mat , 0 , 0 , 0 ) ) ; } }

Index/key variables: i, j
Class/struct names: GFG
Java program:
public class GFG { final static int N = 4 ; static int MaximumDecimalValue ( int mat [ ] [ ] , int n ) { int dp [ ] [ ] = new int [ n ] [ n ] ; if ( mat [ 0 ] [ 0 ] == 1 ) { } for ( int i = 1 ; i < n ; i ++ ) { if ( mat [ 0 ] [ i ] == 1 ) { dp [ 0 ] [ i ] = ( int ) ( dp [ 0 ] [ i - 1 ] + Math . 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 ] = ( int ) ( dp [ i - 1 ] [ 0 ] + Math . 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 ] = ( int ) ( Math . max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) + Math . pow ( 2 , i + j ) ) ; } else { dp [ i ] [ j ] = Math . max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ; } } } return dp [ n - 1 ] [ n - 1 ] ; } public static void main ( String [ ] args ) { int mat [ ] [ ] = { { 1 , 1 , 0 , 1 } , { 0 , 1 , 1 , 0 } , { 1 , 0 , 0 , 1 } , { 1 , 0 , 1 , 1 } , } ; System . out . println ( MaximumDecimalValue ( mat , 4 ) ) ; } }

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
public class GFG { static int CountPS ( char str [ ] , int n ) { int dp [ ] [ ] = new int [ n ] [ n ] ; boolean P [ ] [ ] = new boolean [ n ] [ n ] ; 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 ] ; } public static void main ( String [ ] args ) { String str = " abaab " ; System . out . println ( CountPS ( str . toCharArray ( ) , str . length ( ) ) ) ; } }

Index/key variables: i, j, n
Accumulator variables: gap, i
Iterator variables: gap, i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int maxSumWO3Consec ( int arr [ ] , int n ) { int sum [ ] = new int [ n ] ; if ( n >= 1 ) sum [ 0 ] = arr [ 0 ] ; if ( n >= 2 ) sum [ 1 ] = arr [ 0 ] + arr [ 1 ] ; if ( n > 2 ) sum [ 2 ] = Math . max ( sum [ 1 ] , Math . max ( arr [ 1 ] + arr [ 2 ] , arr [ 0 ] + arr [ 2 ] ) ) ; for ( int i = 3 ; i < n ; i ++ ) sum [ i ] = Math . max ( Math . max ( sum [ i - 1 ] , sum [ i - 2 ] + arr [ i ] ) , arr [ i ] + arr [ i - 1 ] + sum [ i - 3 ] ) ; return sum [ n - 1 ] ; } public static void main ( String [ ] args ) { int arr [ ] = { 100 , 1000 , 100 , 1000 , 1 } ; int n = arr . length ; System . out . println ( maxSumWO3Consec ( arr , n ) ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static int maxSumPairWithDifferenceLessThanK ( int arr [ ] , int N , int K ) { Arrays . sort ( arr ) ; int dp [ ] = new int [ 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 ] = Math . max ( dp [ i ] , dp [ i - 2 ] + arr [ i ] + arr [ i - 1 ] ) ; else dp [ i ] = Math . max ( dp [ i ] , arr [ i ] + arr [ i - 1 ] ) ; } } return dp [ N - 1 ] ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 5 , 10 , 15 , 17 , 12 , 9 } ; int N = arr . length ; int K = 4 ; System . out . println ( maxSumPairWithDifferenceLessThanK ( arr , N , K ) ) ; } }

Index/key variables: N, i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { public static int lucas ( int n ) { if ( n == 0 ) return 2 ; if ( n == 1 ) return 1 ; return lucas ( n - 1 ) + lucas ( n - 2 ) ; } public static void main ( String args [ ] ) { int n = 9 ; System . out . println ( lucas ( n ) ) ; } }

Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int breakSum ( int n ) { if ( n == 0 n == 1 ) return n ; return Math . max ( ( breakSum ( n / 2 ) + breakSum ( n / 3 ) + breakSum ( n / 4 ) ) , n ) ; } public static void main ( String [ ] args ) { int n = 12 ; System . out . println ( breakSum ( n ) ) ; } }

Class/struct names: GFG
Java program:
public class GFG { static int countPS ( String str ) { int N = str . length ( ) ; int [ ] [ ] cps = new int [ N ] [ N ] ; 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 . charAt ( i ) == str . charAt ( 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 ] ; } public static void main ( String args [ ] ) { String str = " abcb " ; System . out . println ( " Total ▁ palindromic ▁ " + " subsequence ▁ are ▁ : ▁ " + countPS ( str ) ) ; } }

Index/key variables: N, i, k
Accumulator variables: L, i
Iterator variables: L, i
Class/struct names: GFG
Java program:
class GFG { static int n ; static int [ ] [ ] dp = new int [ 1000 ] [ 1000 ] ; static String str = " abcb " ; static 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 . charAt ( i ) == str . charAt ( 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 ) ; } public static void main ( String [ ] args ) { for ( int i = 0 ; i < 1000 ; i ++ ) for ( int j = 0 ; j < 1000 ; j ++ ) dp [ i ] [ j ] = - 1 ; n = str . length ( ) ; System . out . println ( " Total ▁ palindromic ▁ subsequence " + " are ▁ : ▁ " + countPS ( 0 , n - 1 ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int countSub ( int arr [ ] , int n ) { int count [ ] = new int [ 10 ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = arr [ i ] - 1 ; j >= 0 ; j -- ) count [ arr [ i ] ] += count [ j ] ; count [ arr [ i ] ] ++ ; } int result = 0 ; for ( int i = 0 ; i < 10 ; i ++ ) result += count [ i ] ; return result ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 2 , 4 , 5 , 4 } ; int n = arr . length ; System . out . println ( countSub ( arr , n ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, result
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int minimum ( int a , int b , int c ) { return Math . min ( Math . min ( a , b ) , c ) ; } static int findMinSum ( int arr [ ] , int n ) { int sum [ ] = new int [ n ] ; sum [ 0 ] = arr [ 0 ] ; sum [ 1 ] = arr [ 1 ] ; sum [ 2 ] = arr [ 2 ] ; for ( int i = 3 ; i < n ; i ++ ) sum [ i ] = arr [ i ] + minimum ( sum [ i - 3 ] , sum [ i - 2 ] , sum [ i - 1 ] ) ; return minimum ( sum [ n - 1 ] , sum [ n - 2 ] , sum [ n - 3 ] ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 20 , 2 , 10 , 1 } ; int n = arr . length ; System . out . println ( " Min ▁ Sum ▁ is ▁ " + findMinSum ( arr , n ) ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { public static int MinimumCost ( int cost [ ] , int n , int W ) { Vector < Integer > val = new Vector < Integer > ( ) ; Vector < Integer > wt = new Vector < Integer > ( ) ; int size = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( cost [ i ] != - 1 ) { val . add ( cost [ i ] ) ; wt . add ( i + 1 ) ; size ++ ; } } n = size ; int min_cost [ ] [ ] = new int [ n + 1 ] [ W + 1 ] ; for ( int i = 0 ; i <= W ; i ++ ) min_cost [ 0 ] [ i ] = Integer . MAX_VALUE ; for ( int i = 1 ; i <= n ; i ++ ) min_cost [ i ] [ 0 ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= W ; j ++ ) { if ( wt . get ( i - 1 ) > j ) min_cost [ i ] [ j ] = min_cost [ i - 1 ] [ j ] ; else min_cost [ i ] [ j ] = Math . min ( min_cost [ i - 1 ] [ j ] , min_cost [ i ] [ j - wt . get ( i - 1 ) ] + val . get ( i - 1 ) ) ; } } return ( min_cost [ n ] [ W ] == Integer . MAX_VALUE ) ? - 1 : min_cost [ n ] [ W ] ; } public static void main ( String [ ] args ) { int cost [ ] = { 1 , 2 , 3 , 4 , 5 } , W = 5 ; int n = cost . length ; System . out . println ( MinimumCost ( cost , n , W ) ) ; } }

Index/key variables: W, i, j, n
Accumulator variables: i, j, size
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int count ( String a , String b , int m , int n ) { if ( ( m == 0 && n == 0 ) n == 0 ) return 1 ; if ( m == 0 ) return 0 ; if ( a . charAt ( m - 1 ) == b . charAt ( n - 1 ) ) return count ( a , b , m - 1 , n - 1 ) + count ( a , b , m - 1 , n ) ; else return count ( a , b , m - 1 , n ) ; } public static void main ( String [ ] args ) { String a = " GeeksforGeeks " ; String b = " Gks " ; System . out . println ( count ( a , b , a . length ( ) , b . length ( ) ) ) ; } }

Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int lcs ( String X , String Y , int m , int n ) { int L [ ] [ ] = new int [ 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 . charAt ( i - 1 ) == Y . charAt ( j - 1 ) ) L [ i ] [ j ] = L [ i - 1 ] [ j - 1 ] + 1 ; else L [ i ] [ j ] = Math . max ( L [ i - 1 ] [ j ] , L [ i ] [ j - 1 ] ) ; } } return L [ m ] [ n ] ; } static int findMinCost ( String X , String Y , int costX , int costY ) { int m = X . length ( ) ; int n = Y . length ( ) ; int len_LCS ; len_LCS = lcs ( X , Y , m , n ) ; return costX * ( m - len_LCS ) + costY * ( n - len_LCS ) ; } public static void main ( String [ ] args ) { String X = " ef " ; String Y = " gh " ; System . out . println ( " Minimum ▁ Cost ▁ to ▁ make ▁ two ▁ strings ▁ " + " ▁ identical ▁ is ▁ = ▁ " + findMinCost ( X , Y , 10 , 20 ) ) ; } }

Index/key variables: i, j, m, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . ArrayList ; import java . util . Arrays ; import java . util . Collections ; import java . util . Comparator ; class Graph { static class Job { int start , finish , profit ; public Job ( int start , int finish , int profit ) { this . start = start ; this . finish = finish ; this . profit = profit ; } } ; static int findSum ( ArrayList < Job > arr ) { int sum = 0 ; for ( int i = 0 ; i < arr . size ( ) ; i ++ ) sum += arr . get ( i ) . profit ; return sum ; } static void findMaxProfit ( ArrayList < Job > arr ) { Collections . sort ( arr , new Comparator < Job > ( ) { @ Override public int compare ( Job x , Job y ) { return x . start - y . start ; } } ) ; ArrayList < ArrayList < Job > > L = new ArrayList < > ( ) ; for ( int i = 0 ; i < arr . size ( ) ; i ++ ) { L . add ( new ArrayList < > ( ) ) ; } L . get ( 0 ) . add ( arr . get ( 0 ) ) ; for ( int i = 1 ; i < arr . size ( ) ; i ++ ) { for ( int j = 0 ; j < i ; j ++ ) { if ( ( arr . get ( j ) . finish <= arr . get ( i ) . start ) && ( findSum ( L . get ( j ) ) > findSum ( L . get ( i ) ) ) ) { ArrayList < Job > copied = new ArrayList < > ( L . get ( j ) ) ; L . set ( i , copied ) ; } } L . get ( i ) . add ( arr . get ( i ) ) ; } ArrayList < Job > maxChain = new ArrayList < > ( ) ; for ( int i = 0 ; i < L . size ( ) ; i ++ ) if ( findSum ( L . get ( i ) ) > findSum ( maxChain ) ) maxChain = L . get ( i ) ; for ( int i = 0 ; i < maxChain . size ( ) ; i ++ ) { System . out . printf ( "(%d, %d, %d)NEW_LINE", maxChain . get ( i ) . start , maxChain . get ( i ) . finish , maxChain . get ( i ) . profit ) ; } } public static void main ( String [ ] args ) { Job [ ] a = { new Job ( 3 , 10 , 20 ) , new Job ( 1 , 2 , 50 ) , new Job ( 6 , 19 , 100 ) , new Job ( 2 , 100 , 200 ) } ; ArrayList < Job > arr = new ArrayList < > ( Arrays . asList ( a ) ) ; findMaxProfit ( arr ) ; } }

Accumulator variables: i, j, sum
Iterator variables: i, j
Class/struct names: Graph, Job
Java program:
import java . util . * ; class GFG { static int N = 100 ; static int [ ] [ ] L = new int [ N ] [ N ] ; static Set < String > findLCS ( String X , String Y , int m , int n ) { Set < String > s = new HashSet < > ( ) ; if ( m == 0 n == 0 ) { s . add ( " " ) ; return s ; } if ( X . charAt ( m - 1 ) == Y . charAt ( n - 1 ) ) { Set < String > tmp = findLCS ( X , Y , m - 1 , n - 1 ) ; for ( String str : tmp ) s . add ( str + X . charAt ( m - 1 ) ) ; } else { if ( L [ m - 1 ] [ n ] >= L [ m ] [ n - 1 ] ) s = findLCS ( X , Y , m - 1 , n ) ; if ( L [ m ] [ n - 1 ] >= L [ m - 1 ] [ n ] ) { Set < String > tmp = findLCS ( X , Y , m , n - 1 ) ; s . addAll ( tmp ) ; } } return s ; } static int LCS ( String X , String Y , int m , int n ) { 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 . charAt ( i - 1 ) == Y . charAt ( j - 1 ) ) L [ i ] [ j ] = L [ i - 1 ] [ j - 1 ] + 1 ; else L [ i ] [ j ] = Math . max ( L [ i - 1 ] [ j ] , L [ i ] [ j - 1 ] ) ; } } return L [ m ] [ n ] ; } public static void main ( String [ ] args ) { String X = " AGTGATG " ; String Y = " GTTAG " ; int m = X . length ( ) ; int n = Y . length ( ) ; System . out . println ( " LCS ▁ length ▁ is ▁ " + LCS ( X , Y , m , n ) ) ; Set < String > s = findLCS ( X , Y , m , n ) ; for ( String str : s ) System . out . println ( str ) ; } }

Index/key variables: N, i, j, m, n
Accumulator variables: i, j
Iterator variables: i, j, str
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int countIntegralSolutions ( int n ) { int result = 0 ; for ( int i = 0 ; i <= n ; i ++ ) for ( int j = 0 ; j <= n - i ; j ++ ) for ( int k = 0 ; k <= ( n - i - j ) ; k ++ ) if ( i + j + k == n ) result ++ ; return result ; } public static void main ( String [ ] args ) { int n = 3 ; System . out . println ( countIntegralSolutions ( n ) ) ; } }

Accumulator variables: i, j, k, result
Iterator variables: i, j, k
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int countIntegralSolutions ( int n ) { return ( ( n + 1 ) * ( n + 2 ) ) / 2 ; } public static void main ( String [ ] args ) { int n = 3 ; System . out . println ( countIntegralSolutions ( n ) ) ; } }

Class/struct names: GFG