Fill rest of the entries in dp [ ] [ ]
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 ; }