• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
2014>
博客园    首页    新随笔    联系   管理    订阅  订阅
牛客第二场A-run
链接: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

dp。dp[i][j]表示到i这一步是跑的(1)还是走的(0)。

#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
long long dp[100005][2];
long long sum[100005];
int main()
{
    long long   n,m;
      scanf("%lld%lld",&n,&m);
     memset(dp,0,sizeof dp);
        dp[0][0]=1;
        for(int i=1;i<=100000;i++)
        {
            dp[i][0]=(dp[i-1][0]+dp[i-1][1])%1000000007;
            if(i>=m)
            dp[i][1]=dp[i-m][0]%1000000007;
        }
        sum[0]=1;
        for(int i=1;i<=100000;i++)
        {
            sum[i]=sum[i-1]+dp[i][0]+dp[i][1];
            sum[i]=sum[i]%1000000007;
        }
    for(int i=0;i<n;i++)
    {
        long long q,w;
        scanf("%lld%lld",&q,&w);
      cout<<(sum[w]+1000000007-sum[q-1])%1000000007<<endl;
    }
    return 0;
}

 

posted on 2018-07-25 10:44  2014>  阅读(146)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3