简单递推....

D. Flowers
time limit per test

1.5 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

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

Input

Input contains several test cases.

The first line contains two integers t and k (1 ≤ t, k ≤ 105), where t represents the number of test cases.

The next t lines contain two integers ai and bi (1 ≤ ai ≤ bi ≤ 105), describing the i-th test.

Output

Print t lines to the standard output. The i-th line should contain the number of ways in which Marmot can eat between ai and bi flowers at dinner modulo 1000000007 (109 + 7).

Sample test(s)
input
3 2
1 3
2 3
4 4

output
6
5
5

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

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>using namespace std;typedef long long int LL;const LL MOD=1000000007;
const int maxn=100100;int t,k;LL tui[maxn];
LL sum[maxn];void TUI(int k)
{tui[1]=1;if(1==k) tui[1]++;tui[0]=1;sum[0]=0;sum[1]=tui[1];for(int i=2;i<maxn;i++){if(i-k>=0) tui[i]=(tui[i-1]+tui[i-k])%MOD;else tui[i]=tui[i-1]%MOD;}for(int i=2;i<maxn;i++){sum[i]=(sum[i-1]+tui[i])%MOD;}
}int main()
{scanf("%d%d",&t,&k);TUI(k);sum[0]=0;while(t--){int l,r;scanf("%d%d",&l,&r);cout<<(sum[r]-sum[l-1]+MOD*2)%MOD<<endl;}return 0;
}

转载于:https://www.cnblogs.com/cxchanpin/p/6978356.html

Codeforces 474 D. Flowers相关推荐

  1. CodeForces 474.D Flowers

    题意: 有n朵花排成一排,小明要么吃掉连续的k朵白花,或者可以吃单个的红花. 给出一个n的区间[a, b],输出总吃花的方法数模 109+7 的值. 分析: 设d(i)表示吃i朵花的方案数. 则有如下 ...

  2. 【CodeForces - 474D】Flowers (线性dp)

    题干: We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we al ...

  3. Codeforces 474 C. Captain Marmot

    4*4*4*4暴力+点的旋转+推断正方型 C. Captain Marmot time limit per test 1 second memory limit per test 256 megaby ...

  4. I - Watering Flowers CodeForces - 617C

    I - Watering Flowers CodeForces - 617C int -2-31 ~ 231-1 == 2e9 longlong -2-63 ~ 263-1 == 9e18 有两种方法 ...

  5. Codeforces - 474D - Flowers - 构造 - 简单dp

    https://codeforces.com/problemset/problem/474/D 这道题挺好的,思路是这样. 我们要找一个01串,其中0的段要被划分为若干个连续k的0. 我们设想一个长度 ...

  6. Divide by Zero 2018 and Codeforces Round #474 (Div. 1 + Div. 2, combined)

    思路:把边看成点,然后每条边只能从下面的边转移过来,我们将边按照u为第一关键字,w为第二关键字排序,这样就能用线段树维护啦. 1 #include<bits/stdc++.h> 2 #de ...

  7. 【codeforces】【比赛题解】#960 CF Round #474 (Div. 1 + Div. 2, combined)

    终于打了一场CF,不知道为什么我会去打00:05的CF比赛-- 不管怎么样,这次打的很好!拿到了Div. 2选手中的第一名,成功上紫! 以后还要再接再厉! [A]Check the string 题意 ...

  8. 【Codeforces】 2A - Winner (map)

    http://codeforces.com/problemset/problem/2/A So, if two or more players have the maximum number of p ...

  9. cf451E. Devu and Flowers(产生不同多重集数量)

    cf451E. Devu and Flowers 题意: 有n个箱子,第i个箱子里有ai朵花,同一个箱子里花的颜色一样,不同箱子里的花颜色不一样.现在在这些箱子里选出m朵花组成一束,求一共有多少种方案 ...

最新文章

  1. 【CSS3】table的css属性
  2. 华为鸿蒙系统如何申请尝鲜,鸿蒙OS 2.0公测尝鲜来咯
  3. 动态规划练习【一】 背包问题
  4. paip.C#.NET多线程访问 toolStripStatusLabel
  5. mac利用vscode运行c语言程序,Mac下使用VScode编译配置C/C++程序详细图文教程
  6. (软件工程复习核心重点)第六章实现和测试-第七节:黑盒测试
  7. Scrapy Crawl 运行出错 AttributeError: 'xxxSpider' object has no attribute '_rules' 的问题解决...
  8. 设备的开发【WP7学习札记之五】
  9. vc开发记牌器的两种思路
  10. 科沃斯扫地机器人无语音提示_科沃斯扫地机器人语音功能,科技or鸡肋?
  11. 【计算机图形学】几何
  12. JavaScript的toast
  13. 中级微观经济学笔记整理
  14. unity 将 .prefab 转换为 txt 格式
  15. 音频编码之aac编码原理
  16. 快准全!极光iAPP在手,APP动态全都有
  17. [js高手之路]jquery插件开发实战-选项卡详解
  18. 音视频学习之ffmpeg常用基础命令整理
  19. 快递100快递java_快递100 java 示例API 返回结果乱码 之替代方案
  20. HMS Core Drive SDK构建使用华为云空间服务应用程序

热门文章

  1. 安装docker环境
  2. html5整个桌面背景图片,HTML5 body设置全屏背景图片 如何让body的背景图片自适应整个屏----实战经验...
  3. jsp mysql 乱码_jsp插入mysql数据库后乱码的解决办法
  4. mysql 面试题笔记_MYSQL面试题(摘抄/个人笔记)
  5. java jnlp_Java Web Start 与jnlp结合实例讲解
  6. 基于redis和R语言构建并行计算平台(yiyou)
  7. python第一个公开发行版_python之基础篇(一)
  8. 内存分配失败错误处理
  9. hashmap扩容_面试官问:HashMap在并发情况下为什么造成死循环?一脸懵
  10. 自动拼图android github,GitHub - zero0011/Puzzle: 拼图游戏 , 可自动实现 拼图操作