Make Numbers with Division
Time limit1sMemory limit1024 MB
Given how many copies of each number 1 to 9 are available, count the distinct values reachable with division and parentheses, modulo 998244353.
- Level
Hard9 of 10
- Topics
- Math, Combinatorics, Dynamic programming
- Solved
- No attempts yet
Problem
Sebin has several nonzero numbers.
Sebin lays out all of these numbers in a row without concatenating them, and writes one division sign between each pair of adjacent numbers. Then he adds parentheses as many times as he likes to form a valid expression, evaluates it, and tries to make a number.
Suppose Sebin has 1, 2, 3, 4, and 6. Sebin can make the following numbers.
The numbers that can be made this way are 1144, 136, 116, 19, 14, 49, 1, 94, 4, 9, 16, 36, and 144. That is 13 numbers in total.
Sebin has copies of the number . Sebin wants to count how many numbers he can make. The number of ways to arrange the numbers and the number of ways to place parentheses both grow very quickly as the count increases, so Sebin needs help counting the numbers he can make.
Input
The first line contains the number of test cases . ()
Each test case is given on one line with 9 integers separated by spaces. (, )
Output
For each test case, print on one line the number of numbers that can be made, modulo 998 244 353.