Resizing the variables
for ( int i = 0 ; i < k ; i ++ ) { exp_c . Add ( 0 ) ; } exp_c [ 0 ] = 1 ; for ( int i = 1 ; i < k ; i ++ ) { exp_c [ i ] = ( exp_c [ i - 1 ] * ( c + 1 ) ) ; } for ( int i = 0 ; i < n ; i ++ ) { dp . Add ( new List < int > ( ) ) ; } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < ( exp_c [ k - 1 ] * ( c + 1 ) ) ; j ++ ) { dp [ i ] . Add ( 0 ) ; } } for ( int i = 0 ; i < n ; i ++ ) { v . Add ( new List < bool > ( ) ) ; } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < ( exp_c [ k - 1 ] * ( c + 1 ) ) ; j ++ ) { v [ i ] . Add ( false ) ; } }