(This problem was inspired by a nice sketch of a 2014 Christmas theater play at FME )
Consider persons and activities. For every person, we know the activities where he or she excels. Print all the ways to assign one activity to each person. All people must excel in their assigned activities, and no activity can be assigned more than once.
Input consists in several cases. Every case begins with
and the names of the
persons in alphabetical order. Follow
,
and the names of the
activities in alphabetical order. Finally, we have a matrix
,
where at the column
of the row
we have a 1 if person
excels in
,
and we have a 0 otherwise. You can assume
,
and that there are no repeated words.
For each case, print all the possible assignments. Inside every combination, persons must be sorted alphabetically. Combinations must be sorted lexicographically by activity. Print a line with 20 dots at the end of every combination, and a line with 30 dashes at the end of every case.
Input
4 Enric Jordi Julia Salvador 4 geocaching muntanyisme sadisme teatre 0 1 0 0 1 0 0 0 0 0 0 1 0 0 1 0 2 Anna Ivet 3 dormir jugar menjar 1 1 0 1 1 1
Output
Enric muntanyisme Jordi geocaching Julia teatre Salvador sadisme .................... ------------------------------ Anna dormir Ivet jugar .................... Anna dormir Ivet menjar .................... Anna jugar Ivet dormir .................... Anna jugar Ivet menjar .................... ------------------------------