Initializing the first value of matrix
tab [ 0 ] [ 0 ] = 1 ; for ( int i = 1 ; i <= sum ; i ++ ) tab [ 0 ] [ i ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) tab [ i ] [ 0 ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= sum ; j ++ ) {