Sadism P36909


Statement
 

pdf   zip

(This problem was inspired by a nice sketch of a 2014 Christmas theater play at FME )

Consider nn persons and mm 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

Input consists in several cases. Every case begins with nn and the names of the nn persons in alphabetical order. Follow mm, and the names of the mm activities in alphabetical order. Finally, we have a matrix n×mn \times m, where at the column jj of the row ii we have a 1 if person ii excels in jj, and we have a 0 otherwise. You can assume 1nm101 \le n \le m \le 10, and that there are no repeated words.

Output

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.

Public test cases
  • 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
    ....................
    ------------------------------
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Salvador Roura
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++