#P8089. 『JROI-5』Color

    ID: 9177 远端评测题 500ms 128MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划 DP2022O2优化树形 DP洛谷月赛

『JROI-5』Color

Background

[Image deleted by March.]

Takizawa March Orz.


The deleted image will be secretly shown to the students who sign up for the editorial session (

Problem Description

Please note the unusual time limit.

Little C has a complete binary tree with depdep levels and nn nodes. She wants to choose one connected subgraph that contains the root node and color it. She wants to know how many different coloring schemes there are. Output the answer modulo 998,244,353998,244,353.

Input Format

Multiple test cases. The first line contains an integer TT, the number of test cases.

For each test case:

The first line contains an integer depdep, as described above.

The second line contains an integer ss, the number of leaf nodes on the bottom level. In particular, it will be given in binary: you will read a depdep-bit 01\texttt{01} string to represent ss. If the binary representation has fewer than depdep bits, it is padded with leading 00.

It is guaranteed that the input is valid.

Output Format

For each test case, output one integer per line, the number of valid coloring schemes. A newline is required.

1
2
10
4
1
3
100
25
1
3
010
10
见附件
见附件

Hint

You can learn the terms used in this statement by reading OI-Wiki Tree Basics.

[Sample Explanation]

For sample #1, you can draw the following binary tree.

7sc6Yj.png

We label this binary tree in preorder traversal (as shown in the figure), obtaining the vertex set (1,2,3)\left(1,2,3\right).

Then only $\left(1,2,3\right),\left(1,2\right),\left(1,3\right),\left(1\right)$ are valid coloring schemes.


For sample #3, you can draw the following binary tree.

7sc1eO.png

We label this binary tree in preorder traversal (as shown in the figure), obtaining the vertex set (1,2,3,4,5)\left(1,2,3,4,5\right).

Then only $\left(1,2,3,4,5\right),\left(1,2,3,4\right),\left(1,2,3\right),\left(1,2,4\right),\left(1,2\right),\left(1,2,3,5\right),\left(1,2,4,5\right),\left(1,2,5\right),\left(1,5\right),\left(1\right)$ are valid coloring schemes.

Obviously, (2,3,4)\left(2,3,4\right) and (1,3,4)\left(1,3,4\right) are not valid coloring schemes: the former does not include the root node, and the latter is not connected.


For 30%30\% of the testdata, 1T10,1dep201\leq T\leq 10, 1\leq dep \leq 20.

For another 20%20\% of the testdata, the tree is a full binary tree (i.e. a perfect binary tree).

For 100%100\% of the testdata, 1T10,1dep1061\leq T\leq 10, 1\leq dep \leq 10^6.

Input Format

Output Format

Hint

Translated by ChatGPT 5