【CODEFORCES】 D. Flowers
来源:互联网 发布:域名虚拟主机哪家好 编辑:程序博客网 时间:2024/06/09 05:16
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 modulo 1000000007 (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 <cstdio>#include <cstdlib>using namespace std;int t,k,a[100005],b[100005],max1;long long d[100005],ans,sum[100005];int main(){ max1=0; scanf("%d%d",&t,&k); for (int i=0;i<t;i++) { scanf("%d%d",&a[i],&b[i]); max1=max(b[i],max1); } d[0]=1; if (k==1) d[1]=2; else d[1]=1; for (int i=2;i<k;i++) d[i]=d[i-1]; for (int i=k;i<=max1;i++) d[i]=(d[i-1]+d[i-k])%1000000007; sum[0]=d[0]; for (int i=1;i<=max1;i++) sum[i]=(sum[i-1]+d[i])%1000000007; for (int i=0;i<t;i++) printf("%I64d\n",((sum[b[i]]+d[a[i]])%1000000007-sum[a[i]]%1000000007+1000000007)%1000000007); return 0;}
- Codeforces 474 D. Flowers
- 【CODEFORCES】 D. Flowers
- Codeforces 474D Flowers
- codeforces-474D-Flowers
- Codeforces 474 D Flowers
- Codeforces 474D Flowers
- codeforces 474D Flowers dp
- Codeforces 474d Flowers | dp
- CodeForces 474D Flowers (dp)
- CodeForces 474D Flowers (dp)
- Codeforces 474D Flowers【dp】
- D. Flowers Codeforces Round #271(div2)
- Codeforces 474D Flowers dp(水
- Codeforces 474D Flowers 动态规划法
- Codeforces 474 D Flowers(DP)
- Codeforces 474D Flowers 线性DP
- codeforces 474D flowers 普通计数dp
- D. Flowers
- 嵌入式系统基础知识------之嵌入式系统的硬件基础(1.3)
- 1023
- (八十)MapKit放置系统默认大头针和自定义大头针
- 分享到新浪微博
- OC中用字典创建一个具有省市区的应用(简单的字典运用代码)
- 【CODEFORCES】 D. Flowers
- 获取想要格式的时间 simpledateformat
- 【iOS开发之Objective-C】书签管理器项目
- Spring注解注入
- IOS使用Charts
- 类内代码执行顺序
- hdu 5288 OO’s Sequence(15多校第一场1001)
- uva11404(数论_三角形计数)
- 223 Rectangle Area