I have been learning dynamic programming, and I want to take the classic subset sum problem a little further by printing out all the subsets which add up to a number. How exactly would I go about doing this? As of now, I know how to print true or false based on whether there is a subset that adds up to it
public static boolean hasSum(int [] array, int sum)
{
int len = array.length;
boolean[][] table = new boolean[sum+1][len+1];
int i;
for( i = 0; i <= len; i++ )
table[0][i] = true;
for( i = 1; i <= sum; i++ )
table[i][0] = false;
for( i = 1; i <= sum; i++ )
{
for( int j = 1; j <= len; j++ )
{
table[i][j] = table[i][j-1];
if( !table[i][j] && i >= array[j-1] )
table[i][j] = table[i-array[j-1]][j-1];
}
}
return table[sum][len];
}
if possible, I'd like to return an array of all of the subsets.