lgoritmos de permutação em C #
Estou lutando com esse algoritmo que preciso escrever. Estou usando C #.
Diz que tenho umList<Bag>
e eu tenho umList<Lunch>
. Preciso escrever um algoritmo que enumere todas as permutações de almoços em todas as sacola
Por exemplo, digamos que haja 3 almoços e 2 malas:
// 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
As duas permutaçõesBag 1 Lunch 1 and Bag 2 Lunch 2
eBag 1 Lunch 2 and Bag 2 Lunch 1
são diferentes porque os sacos têm capacidades diferentes; portanto, ambos precisam ser enumerado
O número de malas e almoços pode ser qualquer númer
Criei uma classe chamadaBagLunch
que contém um par de malas e almoços. A lista de exemplos que eu dei acima seria armazenada em umList<BagLunch>
.
Obrigado