CodeforcesRound#271(Div.2)D.Flowers(递推预处理)_html/css_WEB-ITnose
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了CodeforcesRound#271(Div.2)D.Flowers(递推预处理)_html/css_WEB-ITnose,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2301字,纯文字阅读大概需要4分钟。
内容图文
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 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<= n < k)
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<<1, l, m#define rson o<<1|1, m+1, rusing namespace std;typedef long long LL;int n = maxn, k, t, a, b, dp[maxn], sum[maxn];int main(){ scanf("%d%d", &t, &k); for(int i = 0; i < k; i++) dp[i] = 1; for(int i = k; i < n; i++) dp[i] = (dp[i-1] + dp[i-k])%mod; for(int i = 1; i < n; i++) sum[i] = (sum[i-1] + dp[i])%mod; while(t--) { scanf("%d%d", &a, &b); printf("%d\n", ((sum[b]-sum[a-1])%mod+mod)%mod ); } return 0;}
??
内容总结
以上是互联网集市为您收集整理的CodeforcesRound#271(Div.2)D.Flowers(递推预处理)_html/css_WEB-ITnose全部内容,希望文章能够帮你解决CodeforcesRound#271(Div.2)D.Flowers(递推预处理)_html/css_WEB-ITnose所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。