eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Girls`Celebration

Girls`Celebration

In order to celebrate the \textbf{100}-th anniversary of Tsinghua University, \textbf{n} girls are planning to hold a party. They're experts at singing and dancing, and they love to perform in groups. In their current design, there will be a stage and a row of seats. When a group of girls need to sing or dance on the stage, they stand up from their seats, and go to the stage. When they've finished performing, they return to their own seat (they don't exchange seats, because every girl has a lot of personal belongings on her seat). They want this procedure look cool, so for each performance, the actresses seats should be consecutive. For example, if there are \textbf{4} girls, and a performance is done by girl \textbf{1}, \textbf{2} and \textbf{4}, then they cannot seat in order of \textbf{1-2-3-4}, since when girl \textbf{1}, \textbf{2} and \textbf{4} stand up, its strange to see a non-actress (girl \textbf{3}) sitting between girl \textbf{2} and \textbf{4}. As I mentioned, they're too good at singing and dancing, so they managed to come up with a lot of combinations. Now they become a bit worried: is there a way to seat all the girls, such that the requirement above can be satisfied (i.e. for every combination, the actresses' seats are consecutive). As a decent programmer, you decide (I know that actually you're being decided, but...) to write a program that can calculate the number of seat arrangements. Since the girls are constantly thinking about new combinations, your program should be able to read new combinations and adjust the answer accordingly. When there are only few possible arrangement (i.e. at most k feasible solutions), your program should output all of them. \InputFile There are several test cases. The first line contains three integers \textbf{n}, \textbf{m}, \textbf{k} (\textbf{1} ≤ \textbf{n}, \textbf{m}, \textbf{k} ≤ \textbf{200}), where \textbf{n} is the number of girls, \textbf{m} is the number of combinations, and \textbf{k} is the parameter described above. Each of the next \textbf{m} lines contains a set of integers, terminated by a zero. These integers are the IDs of the girls in the combination (girls are numbered \textbf{1} to \textbf{n}). The input is terminated by end-of-file (\textbf{EOF}). The size of input file does not exceed \textbf{1} MB. \OutputFile For each new combination, output the number of seat arrangements, after considering this combination. If there is no way, print \textbf{0} and ignore the combination. If there are at most \textbf{k} ways, print them one in a line, in lexicographical order.
Лимит времени 10 секунд
Лимит использования памяти 64 MiB
Входные данные #1
4 4 10
1 2 3 0
2 3 4 0
1 4 0
2 4 0
Выходные данные #1
12
4
1 2 3 4
1 3 2 4
4 2 3 1
4 3 2 1
0
2
1 3 2 4
4 2 3 1