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 ...
随机推荐
- unity还原three之旋转
http://www.360doc.com/content/16/0829/14/12282510_586760119.shtml unity使用左手坐标系,另外在做旋转的时候必须弄清楚旋转坐标轴和旋 ...
- [USACO5.3]量取牛奶Milk Measuring
https://daniu.luogu.org/problemnew/show/P2744 滚动数组压去第一维:前i种木桶 f[j] 量取体积j最少需要几种木桶 g[j] 体积j的最优解是否使用了第 ...
- 从咖啡馆的经营看 Web 应用的扩展
我经营着一家咖啡馆.经营成本同所用的资源成正比. 我的咖啡馆店面大概有一百平方英尺(约九平方米),雇佣了一个咖啡师,一台咖啡机. 营业能力: 每次能够服务一个顾客,用三分钟泡制一杯咖啡,算下来服务一个 ...
- 【Linux】SecureCRT连接Linux乱码
SecureCRT连接linux出现乱码问题.解决方法. 打开SecureCRT-->option-->Session option
- for-in 和 for
本文地址:http://www.cnblogs.com/veinyin/p/8745845.html 1 for for ( var i = 0 ; i < len ; i++ ) for 是 ...
- vue组件之间传值方式解析
vue组件之间传值方式解析一.父组件传到子组件 1.父组件parent代码如下: <template> <div class="parent"> <h ...
- [转]std::set、自定义类型与比较函数
转自:http://www.189works.com/article-42025-1.html 怎样在set中放入自定义类型?这个问题通过谷歌就可以得到不少答案:1.定义一个函数对象并在定义set的时 ...
- gpio口、内核定时器使用
/*申请gpio*/ int gpio_request(unsigned gpio, const char *label); /*设置gpio为输入状态,即设置如(GPH0CON)*/ int gpi ...
- ps查看CPU和内存占用前10的进程
内存增序 ps aux --sort rss 内存减序 ps aux --sort -rss cpu增序 ps auxw --sort=%cpu cpu减序 ps auxw --sort=-%cpu ...
- python3 asyncio官方文档中文版
事件循环基类 事件循环基类 事件循环是由asyncio提供的核心执行装置.它提供了多种服务,包括: 注册.执行和关闭延时调用(超时) 为各种通信创建客户端和服务端传输 为一个外部程序通信启动子进程和相 ...