c++ - Combinations of Multiple Vector's Elements Without Repetition -


I have the number of N vectors, say 3, and they have n elements (not necessarily the same amount) . I have to choose X amount of combinations between them. Choose from vector 2 [n] example:

 std :: vector & lt; Int> v1 (3), v2 (5), v3 (2); 

Can not be a combination from a vector, such as v1 [0] and v1 [1]. how can I do this? I have tried to do everything, but it does not seem to be.

If I understand you correctly, then you have en vectors, each one of the different elements With (call ith vector C-shaped) and you to select the M combination of elements of these vectors without recurrence. Each combination will be elements of N elements, each element from each vector.

The number of possible permutations in this case is a vector-sized product, due to the lack of any type of equation, I call in 'P' and calculate in C ++:

  std :: vector & lt; Size_t> S (n); // ... populate s ... size_t p = 1; For (size_t i = 0; i  

So now between the problem 0 and P -1, M becomes one of the different numbers, then converts all those M numbers into the original vectors in the N index. I can think of some ways to calculate those M numbers, perhaps the easiest way to maintain random numbers, unless you can not find separately (effectively denial sample from distribution).

A little more complex part we can do to convert each of our M number into a vector of the index.

  size_t m = / * ... from M One * /; Std :: vector & lt; Size_t> Indices_m (n); For (size_t i = 0; i  

Which usually has chops in the chucks for each index, such as when 2D arrays are represented as 1D arrays.

Now if we can get N = 3 examples we can get 3 elements of our permutation with

v1 [index [0]] v2 [index [1]] v3 [ Index [2]]

Many different values ​​of M as required as the creation.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

jquery - SimpleModal Confirm fails to submit form -