#P12486. [集训队互测 2024] 木桶效应

    ID: 13490 远端评测题 4000ms 512MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>动态规划 DP集训队互测2024容斥原理

[集训队互测 2024] 木桶效应

Background

The parts that make up an organization are often uneven in quality, and the weaker parts often determine the overall level of the whole organization.

Problem Description

Little D has nn barrels. Each barrel is made of mm wooden planks, and the mm planks are all of different types. For a barrel, if the plank lengths are a1,a2,,ama_1,a_2,\ldots,a_m, then the volume of liquid it can hold is mini=1mai\min_{i=1}^m a_i. Little D’s nn barrels are magical: the profit they produce is not simply the sum of the liquid volumes of each barrel, but the product of the liquid volumes of all barrels. That is, for these nn barrels, if the height of the jj-th plank of the ii-th barrel is pj,ip_{j,i}, then the profit produced by these barrels is i=1n(minj=1mpj,i)\prod_{i=1}^n (\min_{j=1}^m p_{j,i}).

Little D has already bought some planks from the lumber store, but the number of planks in the store is limited. Specifically, for each of the mm types of planks, Little D has exactly one plank of each length from 11 to nn. Little D has now placed qq planks, but he has not decided how to place the remaining planks. Therefore, he wants you to compute the sum of profits over all valid placement schemes. Since this number can be very large, you only need to output the result modulo 998244353998244353.

Formal Statement

There are mm permutations of length nn. Among them, the values at qq positions have been fixed, and the remaining positions are unfixed. Find the sum, over all essentially different permutation groups, of i=1n(minj=1mpj,i)\prod_{i=1}^n (\min_{j=1}^m p_{j,i}), modulo 998244353998244353. Two permutation groups PP and QQ are essentially different if and only if there exist i,ji,j such that Pi,jQi,jP_{i,j}\neq Q_{i,j}. It is guaranteed that at least one valid scheme exists.

Input Format

The first line contains three integers n,m,qn,m,q, with meanings as described above.

The next qq lines each contain three integers x,y,wx,y,w, meaning that px,y=wp_{x,y}=w is required.

Output Format

Output one integer, the sum of contributions of all schemes modulo 998244353998244353.

2 2 0
6
3 2 1
1 1 1
38
50 50 5
6 18 17
10 2 14
43 12 40
11 50 37
45 23 4
830538815

Hint

This problem uses bundled tests.

For all testdata, 1n501\leq n\leq 50, 1m<9982443531\leq m<998244353, 0q100\leq q\leq 10, 1xm1\leq x\leq m, 1y,wn1\leq y,w\leq n.

  • Subtask 1 (4 pts): n5,m3n\leq 5,m\leq 3.
  • Subtask 2 (8 pts): n7,m3n\leq 7,m\leq 3.
  • Subtask 3 (8 pts): m2,q=0m\leq 2,q=0.
  • Subtask 4 (12 pts): q=0q=0.
  • Subtask 5 (16 pts): n20,q5n\leq 20,q\leq 5.
  • Subtask 6 (12 pts): q5q\leq 5.
  • Subtask 7 (20 pts): q7q\leq 7.
  • Subtask 8 (12 pts): q9q\leq 9.
  • Subtask 9 (8 pts): No special constraints.

Translated by ChatGPT 5