Oops, pardon my previous reply (misunderstood you question correctly).
I think this one would suffice:


import java.util.Arrays;

public class Subset {
        public static void main(String[] args) {
                int[] set = { 1, 2, 3, 4 };
                int[] picks = new int[set.length];

                for (int len = 1; len <= set.length; len++) {
                        subset(picks, 0, 0, set, len);
                }
        }

        static void subset(int[] picks, int n, int start, int[] set, int len) {
                if (n == len) {
                        
System.out.println(Arrays.toString(Arrays.copyOfRange(picks, 0, n)));
                } else {
                        for (int i = start; i < set.length; i++) {
                                picks[n] = set[i];
                                subset(picks, n + 1, i + 1, set, len);
                        }
                }
        }
}


--
Best Regards,
Monang





On Mon, May 9, 2011 at 12:16 PM, Reniery O'Hara <[email protected]> wrote:
> Hi Amir,
> could you give some details about the solution you have thought so far?
> regards
>
> On Mon, May 9, 2011 at 10:56 AM, Amir Hossein Sharifzadeh
> <[email protected]> wrote:
>>
>> Dear Friends,
>>
>> I need to a program to find all sorted subsets of a set. There are some
>> recursion solutions for generating subsets, but those are not sorted.
>>
>> However I attend a solution to show me all of sorted subsets of a set.
>> Assume, set includes of numeric values.
>>
>> For example:
>>
>> input numbers = {1,2,3,4}
>>
>> output would be shown as follow down:
>>
>> 1
>> 2
>> 3
>> 4
>>
>> 1,2
>> 1,3
>> 1,4
>> 2,3
>> 2,4
>> 3,4
>>
>> 1,2,3
>> 1,2,4
>> 1,3,4
>> 2,3,4
>>
>> 1,2,3,4
>>
>> I will be very pleased, if someone could provide me with a solution (in
>> java, c or c++)
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "google-codejam" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/google-code?hl=en.
>
>
>
> --
> Reniery
>
> --
> You received this message because you are subscribed to the Google Groups
> "google-codejam" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-code?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"google-codejam" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-code?hl=en.

Reply via email to