0
点赞
收藏
分享

微信扫一扫

牛客网暑期ACM多校训练营(第二场)_A run

眸晓 2023-03-02 阅读 34


链接:​​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


白云 每秒走1m 或者 每秒 跑 k米  不能连续跑哦;

问 白云跑到 L-R 之间 有几种方式

= =dp 不知道怎么写  活活搞成了递推。hhhh 反正也是过了

这是多校 跟队友做出来的第一道题  纪念一下嘻嘻

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;

#define maxn (int)1e5+10
const int Mod=1e9+7 ;
long long int n,dp[maxn],c[50],m,a[maxn]={0},r;
void dabiao(int k)
{
memset(dp,0,sizeof(dp));
int i=1;
dp[0]=1;
while(i<k)
{
dp[i]=1;
++i;
}
dp[k]=2;
for(int i=k+1;i<=100000;i++)
{
dp[i]=(dp[i-k-1]+dp[i-1])%Mod;
//cout<<dp[i]<<endl;
}
a[1]=1;
for(int i=2;i<=100000;i++)
{
a[i]=(a[i-1]+dp[i])%Mod;
// cout<<a[i]<<endl;
}
}
int main()
{
int q,k,l,r;
cin>>q>>k;
dabiao(k);
while(q--)
{
int ans=0;
cin>>l>>r;
int i=1;
ans=((a[r]%Mod-a[l-1]%Mod)%Mod+Mod)%Mod;
cout<<ans<<endl;
}
return 0;
}

 

举报

相关推荐

0 条评论