CF1552I.Organizing a Music Festival
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are the organizer of the famous "Zurich Music Festival". There will be n singers who will perform at the festival, identified by the integers 1 , 2 , … , n . You must choose in which order they are going to perform on stage.
You have m friends and each of them has a set of favourite singers. More precisely, for each 1≤i≤m , the i -th friend likes singers si,1,si,2,…,si,qi .
A friend of yours is happy if the singers he likes perform consecutively (in an arbitrary order). An ordering of the singers is valid if it makes all your friends happy.
Compute the number of valid orderings modulo 998244353 .
输入格式
The first line contains two integers n and m ( 1≤n,m≤100 ) — the number of singers and the number of friends correspondingly.
The i -th of the next m lines contains the integer qi ( 1≤qi≤n ) — the number of favorite singers of the i -th friend – followed by the qi integers si,1,si,2,…,si,qi ( 1≤si,1<si,2<⋯<si,qi≤n ) — the indexes of his favorite singers.
输出格式
Print the number of valid orderings of the singers modulo 998244353 .
输入输出样例
输入#1
3 1 2 1 3
输出#1
4
输入#2
5 5 2 1 2 2 2 3 2 3 4 2 4 5 2 1 5
输出#2
0
输入#3
100 1 1 50
输出#3
35305197
输入#4
5 1 5 1 2 3 4 5
输出#4
120
输入#5
2 5 1 2 1 2 1 2 1 1 1 1
输出#5
2
输入#6
11 4 5 4 5 7 9 11 2 2 10 2 9 11 7 1 2 3 5 8 10 11
输出#6
384
说明/提示
Explanation of the first sample: There are 3 singers and only 1 friend. The friend likes the two singers 1 and 3 . Thus, the 4 valid orderings are:
- 1 3 2
- 2 1 3
- 2 3 1
- 3 1 2
Explanation of the second sample: There are 5 singers and 5 friends. One can show that no ordering is valid.
Explanation of the third sample: There are 100 singers and only 1 friend. The friend likes only singer 50 , hence all the 100! possible orderings are valid.
Explanation of the fourth sample: There are 5 singers and only 1 friend. The friend likes all the singers, hence all the 5!=120 possible orderings are valid.