开发者

generate all combination

开发者 https://www.devze.com 2023-02-13 12:34 出处:网络
Given buckets of unique numbers, how do we generate all combinations where you choosing a number from each bucket only once.

Given buckets of unique numbers, how do we generate all combinations where you choosing a number from each bucket only once.

For example, if given {1,12,3开发者_如何学C} and {4,22,6} the answer is:

1/4 12/22 3/6

1/4 12/6 3/22

1/22 12/4 3/6

1/22 12/6 3/4

1/6 12/4 3/22

1/6 12/22 3/4

Of course, we don't just want 2 buckets, but n buckets. And each bucket can contain any amount of numbers; the numbers are unique across buckets.

Any algorithm in c# would be appreciated. I would expect the result to be something like: List<List<int[]>>

Thanks!


Take a look at this:

C# Permutation of an array of arraylists?

And this:

Fast permutation -> number -> permutation mapping algorithms

0

精彩评论

暂无评论...
验证码 换一张
取 消