#P16266. [蓝桥杯 2026 省 Python B 组] 星光共鸣
[蓝桥杯 2026 省 Python B 组] 星光共鸣
Problem Description
Xiao Lan is an interstellar explorer. During an ancient ruin exploration, he found a “starlight tablet”.
There are grooves on the tablet from left to right. For each groove, Xiao Lan can choose to embed a “star shard”, denoted as , or leave it empty, denoted as . In this way, the state of the whole tablet can be represented by a binary string of length .
According to the records in the ruin, the tablet resonates with “continuous and complete shard segments”. Specifically, for any contiguous subinterval (), if all grooves in this segment are embedded with shards, that is, every bit in the interval is , then this interval will produce one “starlight resonance”. Otherwise, as long as there is a in it, this interval will not resonate.
Therefore, the “total number of starlight resonances” produced by a filling plan equals the number of contiguous subintervals that are all in its binary string.
For example, when and the tablet state is :
- , , and correspond to , each producing resonance;
- corresponds to , producing another resonance;
- Other subintervals such as corresponding to , and corresponding to , contain , so they do not resonate.
So this state produces a total of resonances.
Now, Xiao Lan plans to enumerate all possible filling plans. Since each groove has only two choices (place or not place), there are different binary strings in total. Xiao Lan wants to know: among these plans, how many plans have a total resonance count of at least ?
Since the answer may be very large, output the result modulo .
Input Format
The input consists of one line containing two integers and , representing the number of grooves on the tablet and the required minimum number of “starlight resonances”.
Output Format
Output one integer, representing the number of states whose “total number of starlight resonances is at least ”. Since the answer may be very large, output it modulo .
4 4
5
Hint
Sample Explanation
When and , there are states that meet the condition:
- : the resonance count is ;
- : the resonance count is ;
- : the resonance count is ;
- : the resonance count is ;
- : the resonance count is .
So the answer is .
Constraints
For of the testdata, it is guaranteed that .
For of the testdata, it is guaranteed that , .
Translated by ChatGPT 5