D. Flowers Codeforces Round #271(div2)
1.5 seconds
256 megabytes
standard input
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 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.
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).
3 2
1 3
2 3
4 4
6
5
5
- 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 <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
const long long mod = 1000000007;
const int maxn=100000;
long long dp[maxn+100];
long long sum[maxn+100];
using namespace std;
int main(){
int n,k;
memset(sum, 0, sizeof(sum));
scanf("%d %d",&n,&k);
sum[0]=0;
dp[0]=1;
for(int i=1;i<k;++i){
dp[i]=1;
sum[i]=sum[i-1]+dp[i];
}
for(int i=k;i<=maxn;++i){
dp[i]=dp[i-1]+dp[i-k];
dp[i]%=mod;
sum[i]=sum[i-1]+dp[i];
sum[i]%=mod;
}
int a,b;
for(int i=0;i<n;++i){
scanf("%d %d",&a,&b);
printf("%I64d\n",(sum[b]-sum[a-1]+mod)%mod);
}
return 0;
}
D. Flowers Codeforces Round #271(div2)的更多相关文章
- B. Worms Codeforces Round #271 (div2)
B. Worms time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...
- A. Keyboard Codeforces Round #271(div2)
A. Keyboard time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...
- Codeforces Round #271 (Div. 2)题解【ABCDEF】
Codeforces Round #271 (Div. 2) A - Keyboard 题意 给你一个字符串,问你这个字符串在键盘的位置往左边挪一位,或者往右边挪一位字符,这个字符串是什么样子 题解 ...
- Codeforces Round #539 div2
Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...
- 【前行】◇第3站◇ Codeforces Round #512 Div2
[第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...
- Codeforces Round#320 Div2 解题报告
Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...
- Codeforces Round #564(div2)
Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...
- Codeforces Round #361 div2
ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...
- Codeforces Round #626 Div2 D,E
比赛链接: Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics) D.Present 题意: 给定大 ...
随机推荐
- hdu 2112 HDU Today (floyd算法)
这道题貌似在原来学长给我们的搞的小比赛中出过! 这次又让我遇到,果断拿下! 不过方法很蠢,跑了1000多ms,虽然要求5000ms以内! 题目就是给你一些位置之间的距离,然后再让你求特定的两点之间的距 ...
- python中的__all__和__slots__
python两个有趣属性__all__可用于模块导入时限制,如:from module import *此时被导入模块若定义了__all__属性,则只有all内指定的属性.方法.类可被导入~若没定义, ...
- Bootstrap 3之美07-插件Collapse、Accordion、Modal、Tab、Tooltip、Alert、Carousel
类似Page Header, Breadcrumbs, Dropdowns等,都是Bootstrap的组件,是静态的.如果涉及到交互,Bootstrap提供了插件.这些插件包括: ○ 过渡效果: bo ...
- iOS内存优化及排查方法
1.IBOutlet 对象需要release 2.不停的往UIView,特别是UIScrollView上add相同SubView.一定要记得清除之前的SubView,并且在dealloc函数中执行该方 ...
- Google Admob广告Android全攻略1
一.登录Google AdMob中文官网:http://www.google.cn/ads/admob/ ,注册帐号. 1.点击注册AdMob帐号 2.进入Google帐号注册页面,因为要创建一个 ...
- JSONObject以及json(转)
一.JAR包简介 要使程序 可以运行 必须引入JSON-lib包,JSON-lib包同时依赖于以下的JAR包: 1.commons-lang.jar 2.commons- ...
- E470 外放没声音问题解决
到官网下载声卡驱动.和热键驱动,安装就ok了
- List 集合转换为String
开发中会用到把 List<string> 的内容拼接成以逗号分隔的字符串的形式,现总结如下: 方法一: public String listToString(List list, cha ...
- 卡方检验(Chi-square test/Chi-Square Goodness-of-Fit Test)
什么是卡方检验 卡方检验是一种用途很广的计数资料的假设检验方法.它属于非参数检验的范畴,主要是比较两个及两个以上样本率( 构成比)以及两个分类变量的关联性分析.其根本思想就是在于比较理论频数和实际频数 ...
- 3D屏保: 彩色盘子
一个彩色盘子的屏保 记得小时候在电视上看过一个科普节目,由多个颜色组成的盘子,如果快速旋转起来,会看上去是白色的.于是我就写了这个屏保程序,但发现在计算机上模拟并不是这样的. "RollPl ...