CF2169F.Subsequence Problem

省选/NOI-

通过率:0%

时间限制:4.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Given three integers n,m,kn, m, k, as well as kk arrays of integers of lengths l1,l2,…,lkl_1, l_2, \dots, l_k respectively. We denote the element at position jj in array number ii as ai,ja_{i,j}. In each array, all elements are distinct (but may repeat in different arrays).

We call an array bb of length kk beautiful if for each ii from 11 to kk, the element bib_i is equal to one of the elements of the array aia_i.

We call an array cc perfect if every beautiful array bb can be obtained from array cc by deleting several (possibly zero) elements without changing their order. In other words, array cc is perfect if every beautiful array bb is a subsequence of it.

Your task is to count the number of perfect arrays cc of length nn containing only integers from 11 to mm.

给定三个整数 n,m,kn, m, k,以及 kk 个整数数组,其长度分别为 l1,l2,…,lkl_1, l_2, \dots, l_k。我们用 ai,ja_{i,j} 表示第 ii 个数组中位置 jj 处的元素。在每个数组中,所有元素互不相同(但不同数组之间可以有重复元素)。

我们称一个长度为 kk 的数组 bb 是优美的(beautiful),如果对每个 ii(1≤i≤k1 \le i \le k),元素 bib_i 都等于数组 aia_i 中的某个元素。

我们称一个数组 cc 是完美的(perfect),如果每一个优美的数组 bb 都可以通过从 cc 中删除若干(可能为零)个元素(不改变剩余元素的相对顺序)而得到。换言之,数组 cc 是完美的,当且仅当每一个优美的数组 bb 都是 cc 的一个子序列(subsequence)。

你的任务是:计算长度为 nn、且仅包含 11 到 mm 之间整数的完美数组 cc 的个数。

输入格式

The first line contains three integers n,m,kn, m, k (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5; 5≤m≤1085 \le m \le 10^8; 2≤k≤n2 \le k \le n).

The second line contains kk integers l1,l2,…,lkl_1, l_2, \dots, l_k (1≤li≤51 \le l_i \le 5).

The following kk lines contain the ii-th line with lil_i distinct integers ai,1,ai,2,…,ai,lia_{i,1}, a_{i,2}, \dots, a_{i,l_i} (1≤ai,j≤m1 \le a_{i,j} \le m).

Additional constraint on the input: the sum of lil_i does not exceed nn.

第一行包含三个整数 n,m,kn, m, k(2≤n≤2⋅1052 \le n \le 2 \cdot 10^5;5≤m≤1085 \le m \le 10^8;2≤k≤n2 \le k \le n)。

第二行包含 kk 个整数 l1,l2,…,lkl_1, l_2, \dots, l_k(1≤li≤51 \le l_i \le 5)。

接下来的 kk 行中,第 ii 行包含 lil_i 个互不相同的整数 ai,1,ai,2,…,ai,lia_{i,1}, a_{i,2}, \dots, a_{i,l_i}(1≤ai,j≤m1 \le a_{i,j} \le m)。

输入的额外约束:所有 lil_i 的总和不超过 nn。

输出格式

Print one integer — the number of perfect arrays of length nn such that they contain only integers from 11 to mm. Since the answer may be very large, output it modulo 998244353998244353.

输出一个整数——长度为 nn 且仅包含 11 到 mm 之间整数的完美数组的个数。由于答案可能非常大,请对 998244353998244353 取模后输出。

输入输出样例

  • 输入#1

    4 5 3
    1 1 2
    4
    1
    4 3

    输出#1

    2
  • 输入#2

    3 5 2
    1 1
    5
    2

    输出#2

    13
  • 输入#3

    200000 12345678 7
    3 2 5 1 3 4 5
    42 13 37
    37 13
    1 2 3 4 5
    3
    3 1 4
    1 5 9 2
    1 2 3 4 5

    输出#3

    152094503

说明/提示

In the first example, there are two beautiful arrays: [4,1,4][4, 1, 4] and [4,1,3][4, 1, 3]. Only two arrays of length 44 contain both of these arrays as subsequences: [4,1,4,3][4, 1, 4, 3] and [4,1,3,4][4, 1, 3, 4].

In the second example, there is only one beautiful array: [5,2][5, 2]. There are 1313 arrays of length 33 with integers from 11 to 55 that contain it as a subsequence.

在第一个例子中,有两个优美的数组:[4,1,4][4, 1, 4] 和 [4,1,3][4, 1, 3]。仅有两个长度为 44 的数组同时以这两个数组作为子序列:[4,1,4,3][4, 1, 4, 3] 和 [4,1,3,4][4, 1, 3, 4]。

在第二个例子中,仅有一个优美的数组:[5,2][5, 2]。共有 1313 个长度为 33、元素取自 11 到 55 的数组,使得该数组为其子序列。

输入解题思路,AI测评打分。不知道怎么写?

首页