DevX Home Today's Headlines   Articles Archive   Tip Bank   Forums

1. Registered User
Join Date
Aug 2005
Posts
2

## Permutating integer vectors

Hi everyone,

I'm trying to construct certain sets of vectors using C++, but I'm a very beginner.. Major problem at the moment is that how can I permutate vectors? If I have for example vector (consisting of integers)

(1,1,2,0,...,0)

of certain length, how can I obtain the set of vectors where's two 1's, one 2 in any position and other components are 0's?

So the eventual set would look something like

{(1,1,2,0,...,0), (1,2,1,0,...,0), (2,1,1,0,...,0), (0,1,0,1,2,0,...,0) + all other combination with 1,1,2, and lenght-3 zeros}.

Actually what I really need (the above would help me a lot already) is that I'm constructing sets of integer vectors, for which the sum of the squares of the components doesn't exceed some given maximal value. so if the maximal value would for ex. be 6 and the length of the vectors 8, then the vector

(1,1,2,0,0,0,0,0) would belong to the set, as 1^2+1^2+2^2 = 6 but

the vector

(2,2,0,...,0) would not, as 2^2+2^2 = 8.

I hope someone more skilled than me can help me! Thanks in advance,

johan

The bottom line: use std::next_permutation() to obtain the vector's permutations.

3. Registered User
Join Date
Aug 2005
Posts
2
thanks, danny! but... still didn't quite get it. got you offer me something more specific? because in my vectors the components may be equal so i don't quite see how this fits to my case? or is there some way to permutate the indices somehow and in that way get the components permutated? any help is more than welcome, i'm getting desperate!! thanks again in advance,

johan

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 FAQ Latest Articles Java .NET XML Database Enterprise