#P5664. [CSP-S 2019] Emiya 家今天的饭

    ID: 6411 远端评测题 1000ms 250MiB 尝试: 1 已通过: 1 难度: 7 上传者: 标签>动态规划 DP数学2019容斥原理CSP-S 提高级

[CSP-S 2019] Emiya 家今天的饭

Problem Description

Emiya is a high school student who is good at cooking. He has mastered nn kinds of cooking methods, and uses mm kinds of main ingredients. For convenience, we number cooking methods from 11 to nn, and main ingredients from 11 to mm.

Every dish Emiya makes will use exactly one cooking method and exactly one main ingredient. More specifically, Emiya can make ai,ja_{i,j} different dishes that use cooking method ii and main ingredient jj (1in1 \leq i \leq n, 1jm1 \leq j \leq m). This also means Emiya can make a total of $\sum\limits_{i=1}^{n} \sum\limits_{j=1}^{m} a_{i,j}$ different dishes.

Today, Emiya is going to prepare a meal to treat his good friends Yazid and Rin. However, the three of them have different requirements for how the dishes are combined. More specifically, for a plan (a selection) that contains kk dishes:

  • Emiya will not let everyone go hungry, so he will make at least one dish, i.e. k1k \geq 1.
  • Rin wants to taste dishes made with different cooking methods, so she requires that the cooking methods of all dishes are pairwise different.
  • Yazid does not want to taste too many dishes made from the same ingredient, so he requires that each main ingredient is used in at most half of the dishes (i.e. at most k2\lfloor \frac{k}{2} \rfloor dishes).

Here, x\lfloor x \rfloor is the floor function, meaning the greatest integer not exceeding xx.

These requirements are not hard for Emiya, but he wants to know how many different plans satisfy them. Two plans are different if and only if there exists at least one dish that appears in one plan but not in the other.

Emiya asks you for help. Please compute the number of valid plans, and output the result modulo the prime 998,244,353998,244,353.

Input Format

The first line contains two integers n,mn, m separated by a single space.

Lines 22 to n+1n + 1 each contain mm integers separated by single spaces. On line i+1i + 1, the mm numbers are ai,1,ai,2,,ai,ma_{i,1}, a_{i,2}, \cdots, a_{i,m} in order.

Output Format

Output a single integer: the number of valid plans modulo 998,244,353998,244,353.

2 3 
1 0 1
0 1 1
3
3 3
1 2 3
4 5 0
6 0 0
190
5 5
1 0 0 1 1
0 1 0 1 0
1 1 1 1 0
1 0 1 0 1
0 1 1 0 1
742

Hint

[Sample 1 Explanation]

In this sample, for every pair i,ji, j, Emiya can make at most one dish, so we directly describe a dish by giving the indices of its cooking method and main ingredient.

Valid plans include:

  • Make one dish using cooking method 11 and main ingredient 11, and one dish using cooking method 22 and main ingredient 22.
  • Make one dish using cooking method 11 and main ingredient 11, and one dish using cooking method 22 and main ingredient 33.
  • Make one dish using cooking method 11 and main ingredient 33, and one dish using cooking method 22 and main ingredient 22.

Therefore the output is 3mod998,244,353=33 \bmod 998,244,353 = 3. Note that all plans that contain only one dish are invalid, because the only main ingredient appears in more than half of the dishes, which does not satisfy Yazid’s requirement.

[Sample 2 Explanation]

Emiya must make at least 22 dishes.

The number of valid plans with 22 dishes is 100100.

The number of valid plans with 33 dishes is 9090.

Therefore the total number of valid plans is 100+90=190100 + 90 = 190.

[Constraints]

::cute-table{tuack}

Test Point ID n=n= m=m= ai,j<a_{i,j}<
11 22
22 ^ 33 ^
33 55 22
44 ^ 33
55 1010 22
66 ^ 33
77 1010 22 10001000
88 ^ 33 ^
9129\sim 12 4040 22
131613\sim16 ^ 33
172117\sim21 500500
222522\sim25 100100 20002000 998,244,353998,244,353

For all test points, it is guaranteed that 1n1001 \leq n \leq 100, 1m20001 \leq m \leq 2000, 0ai,j<998,244,3530 \leq a_{i,j} \lt 998,244,353.

Translated by ChatGPT 5