Resizing the variables
for ( int i = 0 ; i < k ; i ++ ) { exp_c . add ( 0 ) ; } exp_c . set ( 0 , 1 ) ; for ( int i = 1 ; i < k ; i ++ ) { exp_c . set ( i , ( exp_c . get ( i - 1 ) * ( c + 1 ) ) ) ; } for ( int i = 0 ; i < n ; i ++ ) { dp . add ( new ArrayList < Integer > ( ) ) ; } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < ( exp_c . get ( k - 1 ) * ( c + 1 ) ) ; j ++ ) { dp . get ( i ) . add ( 0 ) ; } } for ( int i = 0 ; i < n ; i ++ ) { v . add ( new ArrayList < Boolean > ( Arrays . asList ( new Boolean [ ( exp_c . get ( k - 1 ) * ( c + 1 ) ) ] ) ) ) ; } for ( int i = 0 ; i < n ; i ++ ) { Collections . fill ( v . get ( i ) , Boolean . FALSE ) ; }