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 ...
随机推荐
- UIViewController的初始化
UIViewController的初始化一般有两个: -(instancetype)init; -(instancetype)initWithNibName:(NSString *)nibNameOr ...
- 数据分析与展示---Numpy数据存取与函数
简介 一:数据的CSV文件存取(一维或二维) (一)写入文件savetxt (二)读取文件loadtxt 二:多维数据的存取 (一)保存文件tofile (二)读取文件fromfile (三)NumP ...
- python---CMDB配置管理数据库
前戏:项目目的 是一个运维自动化管理项目: 为了减少人工干预,降低人员成本 ---资产管理 --操作管理 避免人员直接操作服务器,使用后台去统一操作 一:实现方式 (一)Agent基于shell命令实 ...
- IT人应当知道的10个行业小内幕
如果你打算从事IT行业或刚进入这个行业,也许本文下面的小内幕会吓到你,因为这些事平常都不会公开讨论的.如果你是IT资深人士,或许你已经遇到其中的大部分了.如果你愿意,请一起来参与讨论吧. 这些内幕大多 ...
- 20155234 2016-2017-2 《Java程序设计》第5周学习总结
20155234 2016-2017-2 <Java程序设计>第5周学习总结 教材学习内容总结 Java中所有错误都会被打包为对象,运用try.catch,可以在错误发生时显示友好的错误信 ...
- PHP面向对象__set(赋值方法)
//类Ren里面的变量都是私有的,子类$r里面直接取是取不到的,正常给变量赋值的方法为$r->__set("age",20);,但是可以直接写成$r->age = 20 ...
- POJ 1128 Frame Stacking (拓扑排序)
题目链接 Description Consider the following 5 picture frames placed on an 9 x 8 array. ........ ........ ...
- Linux环境下如何查看内存CPU和GPU使用情况以及界面标题栏实现
查看内存和CPU 单独查看内存使用情况的命令:free -m 查看内存及cpu使用情况的命令:top 也可以安装htop工具,这样更直观, 安装命令如下:sudo apt-ge ...
- java 面试题总结(一)
从网上找了些面试题,自己手工总结了理解了一下,如有理解错误,还请指正. java基础 1.String 为什么是final的? https://www.zhihu.com/question/3 ...
- centos 安装memcache服务后memcahce本机连接Permission
自己手动在虚拟机下装了下memcache,整个过程真是充满波折,本身用php5.3安装memcache扩展就麻烦很多,无法通过yum直接安装,安装方法详见http://chenwei.me/blog/ ...