codeforces474D
Flowers
Input
Output
共t行,每行一个正整数x,表示蛋糕数量在x1-x2之间时,一共能有几种不同的吃法,结果对(10^9+7)取模
Sample Input
Sample Output
6
5
5
Hint
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const ll Mod=;
const int N=;
int T;
ll K;
ll Qzh[N];
ll dp[N];
int main()
{
int i,j;
R(T); R(K);
dp[]=Qzh[]=;
for(i=;i<=;i++)
{
dp[i]+=dp[i-];
if(i>=K) dp[i]+=dp[i-K];
dp[i]-=(dp[i]>=Mod)?Mod:;
Qzh[i]=Qzh[i-]+dp[i];
Qzh[i]-=(Qzh[i]>=Mod)?Mod:;
}
while(T--)
{
int l=read(),r=read();
Wl((Qzh[r]-Qzh[l-]+Mod)%Mod);
}
return ;
}
/*
input
3 2
1 3
2 3
4 4
output
6
5
5
*/
codeforces474D的更多相关文章
随机推荐
- The first day in cnblogs
2018.12.16,学习OI的第4个月零20天,我在博客园开通了属于自己的博客.
- [LOJ#517]. 「LibreOJ β Round #2」计算几何瞎暴力[trie]
题意 题目链接 分析 记操作异或和为 \(tx\) ,最后一次排序时的异或和为 \(ax\) ,每个数插入时的 \(tx\) 记为 \(b\). 我们发现,一旦数列排序,就会变得容易操作. 对于新加入 ...
- Go源码编译安装
参考文档1:https://www.cnblogs.com/majianguo/p/7258975.html 参考文档2:http://www.loongson.cn/news/company/456 ...
- 简单的将Excel数据同步到SqlServer数据库中
1.创建一个WinForm程序,添加一个Button控件 2.Button事件 private void button1_Click(object sender, EventArgs e) { Sys ...
- Python-序列化模块-json-62
序列化模块 Eva_J 什么叫序列化——将原本的字典.列表等内容转换成一个字符串的过程就叫做序列化. 比如,我们在python代码中计算的一个数据需要给另外一段程序使用,那我们怎么给? 现在我们能想到 ...
- long double
long double 输入输出 scanf("%Lf",&a); printf("%.20Lf\n",a);
- Baby Coins
题意 描述 Baby 今天清点自己的百宝箱啦,箱子里有n 种硬币,硬币的面值分别是:val[1],val[2],...,val[n],每种面值的硬币都恰好有2 个. Baby 实在闲的太无聊了,他想从 ...
- 这款APP太像微信 腾讯起诉索赔1000万
去年8月,“币应”(inChat)APP上线,号称是一款原创的区块链加密通讯工具,而界面与微信极为相似,图标是白配绿色调,内部界面几乎一模一样,通讯录.朋友圈的界面完全相同.里面的小游戏,也从微信拿来 ...
- Elasticsearch IK+pinyin
如何在Elasticsearch中安装中文分词器(IK+pinyin) 如果直接使用Elasticsearch的朋友在处理中文内容的搜索时,肯定会遇到很尴尬的问题——中文词语被分成了一个一个的汉字 ...
- spring实例入门
首先是bean文件: package onlyfun.caterpillar; public class HelloBean { private String helloWord = " ...