CF#271 (Div. 2) D Flowers.(dp)
来源:互联网 发布:paparecipe验证软件 编辑:程序博客网 时间:2024/06/05 18:05
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 21 32 34 4
655
- 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 <stdio.h>#include <string>#include <cstring>#include <algorithm>#include <cmath>#define mod 1000000007using namespace std;__int64 dp[100009];__int64 sum[100009];int main(){ int k,t; cin>>t>>k; memset(dp,0,sizeof dp); memset(sum,0,sizeof sum); for(int i=0;i<=100001;i++) { if(i<k) { dp[i]=1; sum[i]=sum[i-1]+dp[i]; } else { 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=1;i<=t;i++) { cin>>a>>b; cout<<(sum[b]-sum[a-1]+mod)%mod<<endl;//由于取模后sum[b]的值可能会小于sum[a]的值,所以要加上mod } return 0;}
- CF#271 (Div. 2) D Flowers.(dp)
- CF#271 (Div. 2) D.(dp)
- Codeforces Round #271 (Div. 2) D. Flowers(DP)
- CF - 474 - D. Flowers(dp)
- CF 474D Flowers(dp)
- CF 474D Flowers DP
- CF 271D Flowers
- CF 196 Div 2 D (树形dp)
- 【Codeforces Round 271 (Div 2)D】【DP】Flowers 黑色必须连续摆放k,长度为n的摆放方案数
- CF Round #424( Div.2) D. Office Keys 【二分||DP】
- CF #301 (Div. 2) D. Bad Luck Island (概率期望dp)
- Codeforces Round #271 (Div. 2) D. Flowers (递推 预处理)
- Codeforces 474 D Flowers(DP)
- CF #244 (Div. 2)D
- CF Round #424( Div.2) D. Office Keys
- codeforces 474D Flowers dp
- Codeforces 474d Flowers | dp
- CodeForces 474D Flowers (dp)
- ㊙ 女士尽量不要称爱人为“老公”
- Android_Fragment解析(2)+Activity通信+防重构_141010
- 如何高效使用github
- iOS block的用法------相当不错的一篇文章
- C语言中的数组
- CF#271 (Div. 2) D Flowers.(dp)
- fzu_1962新击鼓传花游戏 线段树_结点更新_元素位置
- 指针数组和数组指针的区别
- cocosdx 关于CCSpriteFrameCache::sharedSpriteFrameCache()的问题
- IOS设计模式之观察者模式
- [转]前端开发框架对比
- Win7系统上配置使用Intellij Idea 13的SVN插件
- [Java虚拟机读书笔记]3章 垃圾收集器与内存分配策略
- 从哲理小故事中感受哲理