牛客第二场A-run

时间:2023-03-08 23:29:50
牛客第二场A-run
链接:https://www.nowcoder.com/acm/contest/140/A
来源:牛客网 White Cloud is exercising in the playground.
White Cloud can walk 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 integers Q and k.Q is the number of queries.(Q<=,<=k<=)
For the next Q lines,each line contains two integers L and R.(<=L<=R<=)
输出描述:
For each query,print a line which contains an integer,denoting the answer of the query modulo .
示例1
输入
复制 输出
复制

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

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