#P4900. Flowers

    ID: 2537 传统题 2000ms 256MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>动态规划基础算法前缀和CodeForces

Flowers

Flowers

题面翻译

给定正整数 kk。称一个 0101 字符串是好的当且仅当其可以通过把连续 kk11 全部改成 00 来达到全为 00,例如 k=2k=2 时,0000110110110 是好的而 010101 不是好的。

多次询问,每次给定 l,rl,r,询问长度在 [l,r][l,r] 内的 0101 字符串有多少个是好的。由于结果可能过大,答案对 109+710^9+7 取模。

题目描述

We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, some of them white and some of them red.

But, for a dinner to be tasty, there is a rule: Marmot wants to eat white flowers only in groups of size k k .

Now Marmot wonders in how many ways he can eat between a a and b b flowers. As the number of ways could be very large, print it modulo 1000000007 1000000007 ( 109+7 10^{9}+7 ).

输入格式

We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, some of them white and some of them red.

But, for a dinner to be tasty, there is a rule: Marmot wants to eat white flowers only in groups of size k k .

Now Marmot wonders in how many ways he can eat between a a and b b flowers. As the number of ways could be very large, print it modulo 1000000007 1000000007 ( 109+7 10^{9}+7 ).

输出格式

We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, some of them white and some of them red.

But, for a dinner to be tasty, there is a rule: Marmot wants to eat white flowers only in groups of size k k .

Now Marmot wonders in how many ways he can eat between a a and b b flowers. As the number of ways could be very large, print it modulo 1000000007 1000000007 ( 109+7 10^{9}+7 ).

样例 #1

样例输入 #1

3 2
1 3
2 3
4 4

样例输出 #1

6
5
5

提示

  • For K K = 2 2 and length 1 1 Marmot can eat ( R R ).
  • For K K = 2 2 and length 2 2 Marmot can eat ( RR RR ) and ( WW WW ).
  • For K K = 2 2 and length 3 3 Marmot can eat ( RRR RRR ), ( RWW RWW ) and ( WWR WWR ).
  • For K K = 2 2 and length 4 4 Marmot can eat, for example, ( WWWW WWWW ) or ( RWWR RWWR ), but for example he can't eat ( WWWR WWWR ).