CF474D. Flowers
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).
大水,话说这比noip还简单些吧,果然做cf要按x率来做么?\(f[i]=f[i-1]+f[i-k]\)
#include <cstdio>
#include <cstring> const int maxn = 1e5 + ;
const int mod = 1e9 + ; int f[maxn], sum[maxn]; int main() {
int t, k;
scanf("%d%d", &t, &k);
for(int i = ; i < k; ++i) {
f[i] = ;
}
for(int i = k; i <= ; ++i) {
f[i] = f[i - ] + f[i - k];
if(mod <= f[i]) f[i] -= mod;
}
for(int i = ; i <= ; ++i) {
sum[i] = sum[i - ] + f[i];
if(mod <= sum[i]) sum[i] -= mod;
}
while(t--) {
int a, b;
scanf("%d%d", &a, &b);
printf("%d\n", (sum[b] - sum[a - ] + mod) % mod);
} return ;
}

CF474D. Flowers的更多相关文章
- CF474D Flowers 题解
题目:CF474D Flowers 传送门 DP?递推? 首先可以很快看出这是一道 DP 的题目,但与其说是 DP,还不如说是递推. 大家还记得刚学递推时教练肯定讲过的一道经典例题吗?就是爬楼梯,一个 ...
- CF451E Devu and Flowers (隔板法 容斥原理 Lucas定理 求逆元)
Codeforces Round #258 (Div. 2) Devu and Flowers E. Devu and Flowers time limit per test 4 seconds me ...
- poj 3262 Protecting the Flowers
http://poj.org/problem?id=3262 Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Tota ...
- Codeforces Round #381 (Div. 2)B. Alyona and flowers(水题)
B. Alyona and flowers Problem Description: Let's define a subarray as a segment of consecutive flowe ...
- poj1157LITTLE SHOP OF FLOWERS
Description You want to arrange the window of your flower shop in a most pleasant way. You have F bu ...
- CF459B Pashmak and Flowers (水
Pashmak and Flowers Codeforces Round #261 (Div. 2) B. Pashmak and Flowers time limit per test 1 seco ...
- 线段树或树状数组---Flowers
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=4325 Description As is known to all, the blooming tim ...
- sgu 104 Little shop of flowers 解题报告及测试数据
104. Little shop of flowers time limit per test: 0.25 sec. memory limit per test: 4096 KB 问题: 你想要将你的 ...
- 【CodeForces 621C】Wet Shark and Flowers
题 There are n sharks who grow flowers for Wet Shark. They are all sitting around the table, such tha ...
随机推荐
- java基础-BigInteger类常用方法介绍
java基础-BigInteger类常用方法介绍 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.BigInteger类概述 Java中long型为最大整数类型,对于超过long ...
- UIKit类图
- Windows Server2008 R2中的角色
AD Certificate Services 官方说明: Active Directory 证书服务 (AD CS) 提供可自定义的服务,用于颁发和管理使用公钥技术的软件安全系统中的证书.可以使用 ...
- Django 2.0.1 官方文档翻译: 如何安装 django (Page 17)
如何安装 django(Page 17) 这一部分可以让你将 Django 运行起来. 安装 Python 作为 python 的一个 web 框架,Django 依赖 Python.Python 的 ...
- RGB, YUV及相关标准
最近在一次排查问题的过程中发现色彩空间及色彩空间转换也有很多技术细节,而理清这些细节能帮助我们更准确的定位视频方面的问题. 1. 色彩空间 色彩空间一词源于英文的“Color Space”,色彩学中, ...
- 61.volatile关键字
volatile作用 volatile的作用是可以保持共享变量的可见性,即一个线程修改一个共享变量后,另一个线程能够读取到这个修改后的值. 先来看一个问题: 定义一个Task类 package com ...
- 软件测试工程师人手必备的一只:TOM猫,可以带你装逼带你飞!
Hi,你来了? 其实没有猫,为了让你们好好学习,天天向上!我可真的是拼了命了! 写这篇文章的缘由是,近期有同学经常问到一个这样的问题: 老师,tomcat是啥? 老师,Linux是啥? 老师,xshe ...
- css_清除浮动的4种方式
浮动布局和定位布局为css中布局的常用的两种布局方式,而且兼容性会比较好.随着flex的流行,以后会是主流,新的东西好用,兼容不太好.IE10以下不兼容flex布局. float布局会脱离文档流,对页 ...
- transparent 透明效果
background-color:transparent;就是把背景色设置为透明. 实际上background默认的颜色就是透明的属性.所以写和不写都是一样的 span{ width: 0; heig ...
- Flask:静态文件&模板(0.1)
Windows 10家庭中文版,Python 3.6.4,Flask 1.0.2 前面看了Flask的Quickstart文档,可是,一直没有练习里面的内容,这不,刚刚练习完毕,来写篇博文记录一下! ...