Algoritmos de permutación en C #
Estoy luchando con este algoritmo que necesito escribir. Estoy usando C #.
Di que tengo unList<Bag>
y tengo unList<Lunch>
. Necesito escribir un algoritmo que enumere todas las permutaciones de almuerzos en todas las bolsas.
Por ejemplo, digamos que hay 3 almuerzos y 2 bolsas:
// Permutation 1
Bag 1, Lunch 1
Bag 2, Lunch 1
// Permutation 2
Bag 1, Lunch 1
Bag 2, Lunch 2
// Permutation 3
Bag 1, Lunch 1
Bag 2, Lunch 3
// Permutation 4
Bag 1, Lunch 2
Bag 2, Lunch 1
// Permu,tation 5
Bag 1, Lunch 2
Bag 2, Lunch 2
// Permutation 6
Bag 1, Lunch 2
Bag 2, Lunch 3
// Permutation 7
Bag 1, Lunch 3
Bag 2, Lunch 1
// Permutation 8
Bag 1, Lunch 3
Bag 2, Lunch 2
// Permutation 9
Bag 1, Lunch 3
Bag 2, Lunch 3
Las dos permutacionesBag 1 Lunch 1 and Bag 2 Lunch 2
yBag 1 Lunch 2 and Bag 2 Lunch 1
son diferentes porque las bolsas tienen diferentes capacidades, por lo tanto, ambos tendrían que enumerarse.
l número de bolsas y almuerzos puede ser cualquier númer
He creado una clase llamadaBagLunch
que contiene una bolsa y un par de almuerzo. La lista de ejemplos que he dado anteriormente se almacenaría en unaList<BagLunch>
.
Gracias