#P7145. [THUPC 2021 初赛] 合法序列

[THUPC 2021 初赛] 合法序列

Problem Description

For a 00-11 sequence ss of length nn, we number its bits from left to right starting from 00, denoted as s0,s1,,sn1s_0, s_1, \ldots, s_{n-1}.

Given a positive integer kk, take a subsegment of ss with length kk. Interpret this subsegment as a kk-bit binary number with the left side as the most significant bit and the right side as the least significant bit, denoted as tt. Then 0t<2k0 \le t < 2^k.

There are nk+1n - k + 1 subsegments of length kk in ss. If for every such subsegment, after interpreting it as the binary number tt as above, the bit of ss with index tt (that is, sts_t) is 11, then ss is called legal. It is guaranteed that 2kn2^k \le n, so tt will not go out of range as an index of ss.

Given n,kn, k, find the number of legal sequences ss. Since the number of solutions may be large, you only need to output the result modulo 998,244,353998, 244, 353.

Input Format

The input contains one line with two positive integers n,kn, k separated by a space.

It is guaranteed that 1k41 \le k \le 4, 2kn5002^k \le n \le 500.

Output Format

Output one line containing one non-negative integer, which is the number of legal solutions modulo 998,244,353998, 244, 353.

4 2

2

Hint

Sample Explanation #1

There are two sequences that satisfy the requirement: 0,1,1,10, 1, 1, 1 and 1,1,1,11, 1, 1, 1.

Source

From the preliminary round of the 2021 Tsinghua University Programming Contest and Collegiate Invitational (THUPC2021).

Resources such as the editorial can be found at https://github.com/THUSAAC/THUPC2021-pre.

Translated by ChatGPT 5