Codeforces Round #271 (Div. 2) D. Flowers (递推 预处理)_html/css_WEB-ITnose
But, for a dinner to be tasty, there is a rule: Marmot wants to eat white flowers only in groups of sizek.
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
Input contains several test cases.
The first line contains two integers t andk (1?≤?t,?k?≤?105), wheret represents the number of test cases.
The next t lines contain two integers ai andbi (1?≤?ai?≤?bi?≤?105), describing the i-th test.
Output
Print t lines to the standard output. Thei-th line should contain the number of ways in which Marmot can eat betweenai andbi flowers at dinner modulo1000000007 (109?+?7).
Sample test(s)
Input
3 21 32 34 4
Output
655
Note
考虑第n个。假如n是小于k的,那么只能都是是R,也就是只有一种情况。假如大于等于k,如果第n个是W,那么从n-k+1到n全部为W,如果第n个是R,那么数量就是前n-1个的数量。
dp[n] = 1; (0
dp[n] = dp[n-1] + dp[n-k]; (n >= k)
#include#include #include #include #include #include #include #define mem(f) memset(f,0,sizeof(f))#define M 100005#define mod 1000000007#define MAX 0X7FFFFFFF#define maxn 100005#define lson o
??
推荐阅读
-
Codeforces Round #271 (Div. 2) D. Flowers (递推 预处理)_html/css_WEB-ITnose
-
Codeforces Round #FF (Div. 2) D. DZY Loves Modification 贪心+优先队列_html/css_WEB-ITnose
-
Codeforces Round #258 (Div. 2)Devu and Flowers 容斥原理_html/css_WEB-ITnose
-
Codeforces Round #132 (Div. 2) D. Hot Days_html/css_WEB-ITnose
-
Codeforces Round #274 (Div. 2) D. Long Jumps_html/css_WEB-ITnose
-
Codeforces Round #271 (Div. 2) F题 Ant colony(线段树)_html/css_WEB-ITnose
-
Codeforces Round #271 (Div. 2) F题 Ant colony(线段树)_html/css_WEB-ITnose
-
Codeforces Round #FF (Div. 2) D. DZY Loves Modification 贪心+优先队列_html/css_WEB-ITnose
-
Codeforces Round #271 (Div. 2) 解题报告_html/css_WEB-ITnose
-
Codeforces Round #271 (Div. 2)_html/css_WEB-ITnose