|
-
October 21st, 2008, 04:59 AM
#1
How to partition integer with non-duplicated element sequences ?
4=1+3
4=1+1+2
4=1+1+1+1
4=2+2
4=2+1+1 is equivalent to 4=1+1+2
It has been taking me for times, but i haven't found a solution..
-
October 21st, 2008, 05:39 AM
#2
Re: How to partition integer with non-duplicated element sequences ?
I don;t get your question.. is it just at algorithm level ?
Regards,
Ramkrishna Pawar
-
October 21st, 2008, 08:14 AM
#3
Re: How to partition integer with non-duplicated element sequences ?
Basically you want to search for all Combinations versus Permutations right?
if you restrict all lower digits to the left side of the series making up a set then you cannot help but exclude duplicates. What I mean is keep the numbers in order, that way you will not get duplicate combinations.
-
October 21st, 2008, 08:19 AM
#4
Re: How to partition integer with non-duplicated element sequences ?
You can also take a recursive approach, just start each recursion at n.
This will efective keep the number in order as ProgramThis suggested.
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
October 21st, 2008, 09:21 PM
#5
Re: How to partition integer with non-duplicated element sequences ?
 Originally Posted by ProgramThis
Basically you want to search for all Combinations versus Permutations right?
if you restrict all lower digits to the left side of the series making up a set then you cannot help but exclude duplicates. What I mean is keep the numbers in order, that way you will not get duplicate combinations.
i think it is time-consuming to do so, each sequece needs a sorting and then traverse the existed sequences
-
October 21st, 2008, 09:27 PM
#6
Re: How to partition integer with non-duplicated element sequences ?
 Originally Posted by TheCPUWizard
You can also take a recursive approach, just start each recursion at n.
This will efective keep the number in order as ProgramThis suggested.
yes, i did it in recursion, but failed to output the right result when n equals to 6, the sequence-2+2+2 lacks...here is my algorithm,
1.from i = 1 to n/2
2.output i + (n-i)
3.if (n-i) have not partitioned, recursively call the procedure with parameter n-i, else return.
-
October 22nd, 2008, 04:40 PM
#7
Re: How to partition integer with non-duplicated element sequences ?
You also should be passing the value you remove to your recursive method, so you don't remove a value greater than it.
so you'd call part(n - t, t) for t up to n-1
part(n,r) => t + part(n-t, t) for min(n,r) >= t >= 1
part(1,_) => 1
start with part(N,N-1) if you don't want the 4 = 4 case.
Specifically, if your first 2 steps are 6 + 2, you have n=4, r=2. If you only passed in n, then you'd get 4=3+1 as the first case, generating 6=2+3+1, so just passing in n and recursing isn't enough to ensure you generate the combinations in order.
Last edited by pm_kirkham; October 22nd, 2008 at 05:05 PM.
-
October 22nd, 2008, 08:12 PM
#8
Re: How to partition integer with non-duplicated element sequences ?
 Originally Posted by pm_kirkham
You also should be passing the value you remove to your recursive method, so you don't remove a value greater than it.
so you'd call part(n - t, t) for t up to n-1
part(n,r) => t + part(n-t, t) for min(n,r) >= t >= 1
part(1,_) => 1
start with part(N,N-1) if you don't want the 4 = 4 case.
Specifically, if your first 2 steps are 6 + 2, you have n=4, r=2. If you only passed in n, then you'd get 4=3+1 as the first case, generating 6=2+3+1, so just passing in n and recursing isn't enough to ensure you generate the combinations in order.
i didn't get your idea clearly, what's the usage of parameter "r"?
-
October 23rd, 2008, 12:51 PM
#9
Re: How to partition integer with non-duplicated element sequences ?
You don't want to generate combinations which are out of order, such as 6 = 2+3+1, so you pass the value you removed in the previous stage so you don't attempt to remove a value larger than it in the current stage. That value I called r.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|