Alternate way to solve which does not involve permutation-combination

int len = length(N); // for your case of N = 2034, len will be 4

For a number with len digits, there are (len-1) places to place commas
Represent the comma placement possibilties as a (len-1) digit binary 
number, such that in binary representation, 1 represent comma and 0 
represents no comma
----------------
e.g N = 2034
binary 000 ==> 2034
binary 111 ==> 2,0,3,4
binary 010 ==> 20,34
binary 101 ==> 2,03,4
----------------
You should get 2^(len-1) possible values for binary representation
Have you for loop over binary representation combination (simple x = 0 upto 
2^(len-1))
Eliminate repeated cases because of zero

In any case the final count will be 2^(len-1), hence 4 digit number will 
have 16 sets, 6 digit will have 32 sets

Hope it helped

On Friday, 16 November 2012 18:11:27 UTC+5:30, Khalil Sawant wrote:
>
> Looks similar to set partitioning
>
> Try something like this roughly
>
> int len = length(N); // for your case of N = 2034, this will be 4
> int x; // x is number of commas in one set of your aswer
> for (x = 0; x < len; x++) {
> place the comma in x out of (len-1) possible places; /// This will give 
> you (len-1) permutation
> Handle special cases for zero
> }
>
> On Friday, 16 November 2012 16:58:35 UTC+5:30, Amir wrote:
>>
>> Hi,
>>
>> In previous email I posed my questions regarding computing sub-sequences 
>> and operators.
>> But have not received appropriate answer.
>>
>> Therefore, I write another question.
>>
>> I need to generate digit sequences from a number. 
>> Give N= 2034
>> int[] s = reverseDigit(N); // s[] = {2, 0, 3, 4};
>> Now, I need to generate the following set numbers
>> S1 = {2, 0, 3, 4}
>> s2 = {2, 0, 34}
>> s3 = {2, 034} // not acceptable
>> s4 = {20, 3, 4}
>> s5 = {20, 34}
>> s6 = {203, 4}
>> s7 = {2034}
>>
>> I tried, but could not write the code.
>>
>> Thank you very much for assistance.
>> -- Amir 
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-code/-/skptFjya8yoJ.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to