D. Rikka with Subsequences

Codeforces
IDCF10201D
Time4000ms
Memory1024MB
Difficulty
English · Original
Formal · Original
For a known sequence, counting subsequences with a certain remarkable property can depict the sequence itself to a certain extent. Now, Rikka has a sequence $A$ of length $n$ whose elements, denoted by $a_1, a_2, \\\\cdots, a_n$, are positive integers in $[ 1, n ]$. A bridging relation matrix (BRM) is a $n times n$ logical matrix with elements from ${0, 1}$. Here Rikka defines a Yuta subsequence based on a given BRM, $M = (M_{i , j})_(1 <= i , j <= n)$. Rikka calls a subsequence of $A$, denoted by $a_{p_1}, a_{p_2}, \\\\cdots, a_{p_m}$ with $m >= 1$ and $1 <= p_1 < p_2 < \\\\cdots < p_m <= n$, a Yuta subsequence if and only if $M_{a_(p_i} , a_{p_(i + 1})) = 1$ for $i = 1, 2, \\\\cdots, m -1$. Counting the number of different Yuta subsequences has a profound value in data analysis and data recovery. Rikka thinks this task is too simple and she wants to make it look harder and more heuristic. Rikka knows that a Yuta subsequence may appear in the sequence $A$ several times and top programmers may use something like _map, bigInt> cnt_ in C++ or _Map, BigInteger> cnt_ in Java to store all Yuta subsequences and count the numbers. She calls the sum of the cubes of the numbers of occurrences for all Yuta subsequences, which is equal to the sum of cubes of all the second elements in _cnt_, the third coefficient of $A$ over $M$. Now, after showing you the sequence and the BRM, she wants you to calculate the third coefficient of the sequence over the given BRM in modulo $(10^9 + 7)$. The input contains several test cases, and the first line contains a single integer $T$ ($1 <= T <= 20$), the number of test cases. For each test case, the first line contains a single integer $n$ ($1 <= n <= 200$), the length of the sequence $A$. The second line contains $n$ integers $a_1, a_2, \\\\cdots, a_n$ ($1 <= a_i <= n$). The following $n$ lines describe the given BRM, where each line of them has $n$ characters, and the $j$-th character in the $i$-th line of them is either $0$ or $1$, representing the element $M_{i , j}$. For each test case, output a single line with a single integer, the third coefficient of the given sequence over the given BRM in modulo $(10^9 + 7)$. ## Input The input contains several test cases, and the first line contains a single integer $T$ ($1 <= T <= 20$), the number of test cases.For each test case, the first line contains a single integer $n$ ($1 <= n <= 200$), the length of the sequence $A$.The second line contains $n$ integers $a_1, a_2, \\\\cdots, a_n$ ($1 <= a_i <= n$).The following $n$ lines describe the given BRM, where each line of them has $n$ characters, and the $j$-th character in the $i$-th line of them is either $0$ or $1$, representing the element $M_{i , j}$. ## Output For each test case, output a single line with a single integer, the third coefficient of the given sequence over the given BRM in modulo $(10^9 + 7)$. [samples]
**Definitions** Let $ n \in \mathbb{Z}^+ $ be the length of sequence $ A = (a_1, a_2, \dots, a_n) $, where $ a_i \in [1, n] $. Let $ M \in \{0,1\}^{n \times n} $ be the Bridging Relation Matrix (BRM), where $ M_{i,j} = 1 $ indicates a valid transition from value $ i $ to value $ j $. A **Yuta subsequence** is a non-empty subsequence $ A' = (a_{p_1}, a_{p_2}, \dots, a_{p_m}) $ with $ 1 \le p_1 < p_2 < \dots < p_m \le n $ and $ m \ge 1 $, such that $ M_{a_{p_i}, a_{p_{i+1}}} = 1 $ for all $ i \in \{1, 2, \dots, m-1\} $. Let $ \mathcal{S} $ be the multiset of all Yuta subsequences in $ A $, and for each distinct Yuta subsequence $ s \in \mathcal{S} $, let $ c(s) $ denote its number of occurrences (i.e., the number of distinct index sequences producing $ s $). **Constraints** 1. $ 1 \le T \le 20 $ 2. $ 1 \le n \le 200 $ 3. $ 1 \le a_i \le n $ for all $ i \in \{1, \dots, n\} $ 4. $ M_{i,j} \in \{0,1\} $ for all $ i,j \in \{1, \dots, n\} $ **Objective** Compute: $$ \sum_{s \in \mathcal{S}} \left(c(s)\right)^3 \mod (10^9 + 7) $$
API Response (JSON)
{
  "problem": {
    "name": "D. Rikka with Subsequences",
    "description": {
      "content": "For a known sequence, counting subsequences with a certain remarkable property can depict the sequence itself to a certain extent. Now, Rikka has a sequence $A$ of length $n$ whose elements, denoted ",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 4000,
      "memory_limit": 1048576
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10201D"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "For a known sequence, counting subsequences with a certain remarkable property can depict the sequence itself to a certain extent.\n\nNow, Rikka has a sequence $A$ of length $n$ whose elements, denoted ...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z}^+ $ be the length of sequence $ A = (a_1, a_2, \\dots, a_n) $, where $ a_i \\in [1, n] $.  \nLet $ M \\in \\{0,1\\}^{n \\times n} $ be the Bridging Relation Matrix (B...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments