#P16266. [蓝桥杯 2026 省 Python B 组] 星光共鸣

    ID: 18286 远端评测题 3000ms 512MiB 尝试: 0 已通过: 0 显示难度普及 上传者: 标签>动态规划 DP2026蓝桥杯省赛

[蓝桥杯 2026 省 Python B 组] 星光共鸣

Problem Description

Xiao Lan is an interstellar explorer. During an ancient ruin exploration, he found a “starlight tablet”.

There are NN grooves on the tablet from left to right. For each groove, Xiao Lan can choose to embed a “star shard”, denoted as 11, or leave it empty, denoted as 00. In this way, the state of the whole tablet can be represented by a binary string of length NN.

According to the records in the ruin, the tablet resonates with “continuous and complete shard segments”. Specifically, for any contiguous subinterval [l,r][l, r] (1lrN1 \leq l \leq r \leq N), if all grooves in this segment are embedded with shards, that is, every bit in the interval is 11, then this interval will produce one “starlight resonance”. Otherwise, as long as there is a 00 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 11 in its binary string.

For example, when N=4N = 4 and the tablet state is 11011101:

  • [1,1][1,1], [2,2][2,2], and [4,4][4,4] correspond to 11, each producing 11 resonance;
  • [1,2][1,2] corresponds to 1111, producing another 11 resonance;
  • Other subintervals such as [2,3][2,3] corresponding to 1010, and [3,4][3,4] corresponding to 0101, contain 00, so they do not resonate.

So this state produces a total of 44 resonances.

Now, Xiao Lan plans to enumerate all possible filling plans. Since each groove has only two choices (place or not place), there are 2N2^N different binary strings in total. Xiao Lan wants to know: among these plans, how many plans have a total resonance count of at least KK?

Since the answer may be very large, output the result modulo 109+710^9 + 7.

Input Format

The input consists of one line containing two integers NN and KK, 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 KK”. Since the answer may be very large, output it modulo 109+710^9 + 7.

4 4
5

Hint

Sample Explanation

When N=4N = 4 and K=4K = 4, there are 55 states that meet the condition:

  • 11101110: the resonance count is 3+2+1=643 + 2 + 1 = 6 \geq 4;
  • 11011101: the resonance count is (2+1)+1=44(2 + 1) + 1 = 4 \geq 4;
  • 10111011: the resonance count is 1+(2+1)=441 + (2 + 1) = 4 \geq 4;
  • 01110111: the resonance count is 646 \geq 4;
  • 11111111: the resonance count is 4+3+2+1=1044 + 3 + 2 + 1 = 10 \geq 4.

So the answer is 55.

Constraints

For 30%30\% of the testdata, it is guaranteed that N12N \leq 12.

For 100%100\% of the testdata, it is guaranteed that 1N10001 \leq N \leq 1000, 0Kmin(N(N+1)2,100)0 \leq K \leq \min(\frac{N(N+1)}{2}, 100).

Translated by ChatGPT 5