function index = subset_sum_table_to_list ( t, table )

%*****************************************************************************80
%
%% SUBSET_SUM_TABLE_TO_LIST converts a subset sum table to a list.
%
%  Discussion:
%
%    The subset sum problem seeks to construct the value T by summing a 
%    subset of the values W.
%
%    This function takes a table computed by subset_sum_table() and converts
%    it to the corresponding list of values that form the sum.
%
%  Example:
%
%    w = [ 1, 2, 4, 8, 16, 32 ];
%    t = 22;
%
%    table = subset_sum ( w, t, r )
%    table = [ 1, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 
%      16, 16, 16, 16, 16, 16, 16 ]
%
%    index = subset_sum_table_to_list ( t, table );
%    index = [ 2, 4, 16 ]
%
%  Licensing:
%
%    I don't care what you do with this code.
%
%  Modified:
%
%    09 November 2015
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer T, the target value.
%
%    Input, integer TABLE(T), the subset sum table.
%
%    Output, integer INDEX(*), the list of weights that form the sum.
%    If no solution was found, then INDEX is an empty list.
%
  index = [];

  i = t;
  while ( 0 < i )
    index = [ index, table(i) ];
    i = i - table(i);
  end

  return
end
