链接:https://www.nowcoder.com/acm/contest/140/A
来源:牛客网

题目描述

White Cloud is exercising in the playground.
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.

示例1

输入

复制

3 3
3 3
1 4
1 5

输出

复制

2
7
11

思路:

1. dp[i][0]表示到达走着到达i   dp[i][1]表示跑着到达i

ACcode:

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>using namespace std;const int maxn = 1e5+5;
const int mod = 1000000007;int dp[maxn][2];int main(){int K,Q;while(cin>>Q>>K){memset(dp,0,sizeof(dp));for (int i = 1;i<maxn;i++){if ( i<K ) {dp[i][0] = dp[i-1][0] + 1;} else {dp[i][0] = (dp[i-1][0] + dp[i-1][1] + 1) % mod;dp[i][1] = (dp[i-K][0] + 1) % mod;}}int l,r;while(Q--){scanf("%d %d",&l,&r);printf("%d\n",((dp[r][0] + dp[r][1]) % mod - (dp[l-1][0] + dp[l-1][1]) % mod + mod) % mod);}}return 0;
}

牛客网暑期ACM多校训练营(第二场)A .run相关推荐

  1. 牛客网暑期ACM多校训练营(第二场):J. farm(暴力)

    链接:https://www.nowcoder.com/acm/contest/140/J 来源:牛客网 题目描述 White Rabbit has a rectangular farmland of ...

  2. 2018牛客网暑期ACM多校训练营第二场 D - money(贪心)

    题目链接 https://www.nowcoder.com/acm/contest/140#question [题目描述] White Cloud is exercising in the playg ...

  3. 牛客网暑期ACM多校训练营(第十场)F.Rikka with Line Graph

    牛客网暑期ACM多校训练营(第十场)F.Rikka with Line Graph 做法:\(G'\) 中的对应原图两条边(a,b) (c,d)的最短路为: \[ w[a][b] + w[c][d] ...

  4. 牛客网暑期ACM多校训练营(第九场)

    牛客网暑期ACM多校训练营(第九场) A. Circulant Matrix 做法:看到下标 \(xor\) 这种情况就想 \(FWT\),可是半天没思路,于是放弃了..其实这个 \(n\) 疯狂暗示 ...

  5. 牛客网暑期ACM多校训练营(第五场)

    牛客网暑期ACM多校训练营(第五场) A. gpa 二分答案,然后就转化为是否满足 \(\frac {\sum s[i]c[i]}{\sum s[i]} ≥ D\), \(\sum s[i]c[i] ...

  6. 牛客网暑期ACM多校训练营(第三场)

    牛客网暑期ACM多校训练营(第三场) A. PACM Team 01背包,输出方案,用bool存每种状态下用的哪一个物品,卡内存.官方题解上,说用char或者short就行了.还有一种做法是把用的物品 ...

  7. 牛客网暑期ACM多校训练营(第一场)

    牛客网暑期ACM多校训练营(第一场) A. Monotonic Matrix 考虑0和1的分界线,1和2的分界线,发现问题可以转化为两条不互相穿过的路径的方案数(可重叠),题解的做法就是把一条路径斜着 ...

  8. 牛客网暑期ACM多校训练营(第十场)D Rikka with Prefix Sum

    链接:https://www.nowcoder.com/acm/contest/148/D 来源:牛客网 题目描述 Prefix Sum is a useful trick in data struc ...

  9. 牛客网暑期ACM多校训练营(第三场)A.PACM Team(多重01背包)

    链接:https://www.nowcoder.com/acm/contest/141/A 来源:牛客网 题目描述 Eddy was a contestant participating in ACM ...

  10. 2018牛客网暑期ACM多校训练营(第十场)A Rikka with Lowbit (树状数组)

    链接:https://ac.nowcoder.com/acm/contest/148/A 来源:牛客网 Rikka with Lowbit 时间限制:C/C++ 5秒,其他语言10秒 空间限制:C/C ...

最新文章

  1. PDF编辑工具——PDF Desktop Converter 4 Professional
  2. 使用mybatis一次性添加多条数据 在oracle 数据库上
  3. 关于QVariant 的学习一点分享
  4. modelsim的do文件
  5. nginx配置tomcat负载均衡,nginx.conf配置文件的配置
  6. Kibana部署及配置(四)
  7. angular 加入原生html,Angular HTML绑定
  8. SpringBoot整合阿里云OSS文件上传、下载、查看、删除
  9. 如何设计好分布式数据库,这个策略很重要
  10. 电动汽车告急?特斯拉、蔚来之后 一辆比亚迪新能源车突然自燃...
  11. java怎么从数据库中查询_java – 从数据库中检索的实体与查询中的情况相同
  12. rocketmq原理_消息中间件漫谈:RocketMQ延时消息应用及原理剖析
  13. 2018牛客网暑假ACM多校训练赛(第六场)I Team Rocket 线段树
  14. 【Linux】CentOS下vim的配置
  15. Vmware 安装 Fedora 18 注意事项
  16. cmos和ttl_TTL与CMOS集成电路的区分
  17. 过采样 Oversampling
  18. 怎么更改计算机物理地址,如何修改电脑mac地址|电脑修改mac地址的两种方法
  19. 华硕服务器 u盘安装系统,华硕台式机一键U盘装系统win7教程
  20. idr寄存器、_STM32 GPIO寄存器 IDR ODR BSRR BRR

热门文章

  1. 装载M1芯片的Mac安装“AE”时,出现错误代码“501”怎么办?
  2. JavaScript实时获取现货黄金,白银,美元指数价格代码
  3. NXP JN5169 UART 波特率设置
  4. anaconda 创建虚拟环境(自己版本)
  5. 全差分运算放大器ADA4930的分析(2)
  6. 第904题 水果成篮
  7. 加壳工具推荐-无需编程自动化加壳
  8. 在html中控制自动换行 1
  9. C#迭代器的详细用法
  10. ubuntu下添加路径到PATH