2018牛客网暑期ACM多校训练营(第二场) A - run - [DP]
题目链接:https://www.nowcoder.com/acm/contest/140/A
空间限制:C/C++ 131072K,其他语言262144K
64bit IO Format: %lld
题目描述
White Cloud can walk 1 meters or run k meters per second.
Since White Cloud is tired,it can't run for two or more continuous seconds.
White Cloud will move L to R meters. It wants to know how many different ways there are to achieve its goal.
Two ways are different if and only if they move different meters or spend different seconds or in one second, one of them walks and the other runs.
输入描述:
The first line of input contains 2 integers Q and k.Q is the number of queries.(Q<=100000,2<=k<=100000)
For the next Q lines,each line contains two integers L and R.(1<=L<=R<=100000)
输出描述:
For each query,print a line which contains an integer,denoting the answer of the query modulo 1000000007.
输入
3 3
3 3
1 4
1 5
输出
2
7
11
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX=+;
const ll MOD=; int Q,k;
int L,R;
ll dp[MAX][];
//dp[i][0]:最后一步是跑着到 i 米的方案数。
//dp[i][1]:最后一步是走着到 i 米的方案数。
ll sum[MAX]; int main()
{
scanf("%d%d",&Q,&k); memset(dp,,sizeof(dp));
dp[][]=, dp[][]=;
for(int i=;i<=MAX;i++)
{
dp[i+k][]+=dp[i][]; dp[i+k][]%=MOD;
dp[i+][]+=dp[i][]+dp[i][]; dp[i+][]%=MOD;
} sum[]=;
for(int i=;i<=MAX;i++)
{
//printf("%d: %lld %lld\n",i,dp[i][0],dp[i][1]);
sum[i]=(sum[i-]+(dp[i][]%MOD+dp[i][]%MOD)%MOD)%MOD;
} for(int q=;q<=Q;q++)
{
scanf("%d%d",&L,&R);
printf("%lld\n",((sum[R]-sum[L-])+MOD)%MOD);
}
}
2018牛客网暑期ACM多校训练营(第二场) A - run - [DP]的更多相关文章
- 2018牛客网暑期ACM多校训练营(第二场)I- car ( 思维)
2018牛客网暑期ACM多校训练营(第二场)I- car 链接:https://ac.nowcoder.com/acm/contest/140/I来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 ...
- 2018牛客网暑期ACM多校训练营(第一场)D图同构,J
链接:https://www.nowcoder.com/acm/contest/139/D来源:牛客网 同构图:假设G=(V,E)和G1=(V1,E1)是两个图,如果存在一个双射m:V→V1,使得对所 ...
- 2018 牛客网暑期ACM多校训练营(第一场) E Removal (DP)
Removal 链接:https://ac.nowcoder.com/acm/contest/139/E来源:牛客网 题目描述 Bobo has a sequence of integers s1, ...
- 2018牛客网暑期ACM多校训练营(第十场)A Rikka with Lowbit (树状数组)
链接:https://ac.nowcoder.com/acm/contest/148/A 来源:牛客网 Rikka with Lowbit 时间限制:C/C++ 5秒,其他语言10秒 空间限制:C/C ...
- 2018牛客网暑期ACM多校训练营(第十场)J Rikka with Nickname(二分,字符串)
链接:https://ac.nowcoder.com/acm/contest/148/J?&headNav=acm 来源:牛客网 Rikka with Nickname 时间限制:C/C++ ...
- 2018牛客网暑期ACM多校训练营(第二场)J Farm(树状数组)
题意 n*m的农场有若干种不同种类作物,如果作物接受了不同种类的肥料就会枯萎.现在进行t次施肥,每次对一个矩形区域施某种类的肥料.问最后枯萎的作物是多少. 分析 作者:xseventh链接:https ...
- 2018牛客网暑期ACM多校训练营(第一场)B Symmetric Matrix(思维+数列递推)
题意 给出一个矩阵,矩阵每行的和必须为2,且是一个主对称矩阵.问你大小为n的这样的合法矩阵有多少个. 分析 作者:美食不可负064链接:https://www.nowcoder.com/discuss ...
- 2018牛客网暑期ACM多校训练营(第三场) A - PACM Team - [四维01背包][四约束01背包]
题目链接:https://www.nowcoder.com/acm/contest/141/A 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K ...
- 2018牛客网暑期ACM多校训练营(第五场) F - take - [数学期望][树状数组]
题目链接:https://www.nowcoder.com/acm/contest/143/F 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K ...
- 2018牛客网暑期ACM多校训练营(第五场) E - room - [最小费用最大流模板题]
题目链接:https://www.nowcoder.com/acm/contest/143/E 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K ...
随机推荐
- [Scikit-learn] 1.1 Generalized Linear Models - Lasso Regression
Ref: http://blog.csdn.net/daunxx/article/details/51596877 Ref: https://www.youtube.com/watch?v=ipb2M ...
- 爬虫 测试webmagic (一)
目标:统计斗鱼(www.douyu.com)人数 思路: 1. 目录找到douyu播出的所有游戏 http://www.douyutv.com/directory 2. 借助 chrome 定位到每个 ...
- linux下中文文件名乱码解决
在windows上使用ftp上传文件到Linux上,中文名称在Linux系统中显示为乱码.虽然将Linux的env设置了LANG=en_US.UTF-8,并且本地的Shell客户端编码也设置成UTF- ...
- [Ubuntu] apt 添加第三方库
1. 方法一:直接在 /etc/apt/sources.list 添加第三方库. $ sudo vi /etc/apt/sources.list 在其中添加: deb http://archive.s ...
- 不作死就不会死,微软强行插入NO-IP
微软啊微软,你这是何苦来着. 事情经过大致是这样的,微软向美国法院提出起诉No-IP名下22个常用的子域名被恶意软件的作者滥用,要求法官裁定由微软接管No-IP名下的这22个子域名,以便其可以过滤恶意 ...
- linux系统抓包命令
IP地址抓包:tcpdump -i any host 1.1.1.2 -n 端口抓包: tcpdump -i any port 6789 -n wireshak工具抓包:tcp.port == 678 ...
- 【摘】50个jQuery代码段帮助你成为一个更好的JavaScript开发者
今 天的帖子会给你们展示50个jQuery代码片段,这些代码能够给你的JavaScript项目提供帮助.其中的一些代码段是从jQuery1.4.2才 开始支持的做法,另一些则是真正有用的函数或方法,他 ...
- CoreData 数据库更新,数据迁移
本文转载至 http://blog.163.com/djx421@126/blog/static/48855136201411381212985/ 一般程序app升级时,数据库有可能发生改变,如增 ...
- Matlab——filter函数用法
filter:滤波函数,可用来解差分方程. y = filter(b,a,X) [y,zf] = filter(b,a,X) [y,zf] = filter(b,a,X,zi) y = filter( ...
- 【linux】nginx options 跨域问题 请求HTTP错误405 用于访问该页的HTTP动作未被许可 Method Not Allowed
JavaScript JS 跨域问题 HTTP 错误 405 - 用于访问该页的 HTTP 动作未被许可HTTP 错误 405.0 - Method Not Allowed Nginx 处理跨域问题. ...