标签:event 开始 include http 组合数 blank col read lin
Input
Output
共t行,每行一个正整数x,表示蛋糕数量在x1-x2之间时,一共能有几种不同的吃法,结果对(10^9+7)取模
Sample Input
Sample Output
6
5
5
Hint
#include <bits/stdc++.h> using namespace std; typedef long long ll; inline ll read() { ll s=0; bool f=0; char ch=‘ ‘; while(!isdigit(ch)) { f|=(ch==‘-‘); ch=getchar(); } while(isdigit(ch)) { s=(s<<3)+(s<<1)+(ch^48); ch=getchar(); } return (f)?(-s):(s); } #define R(x) x=read() inline void write(ll x) { if(x<0) { putchar(‘-‘); x=-x; } if(x<10) { putchar(x+‘0‘); return; } write(x/10); putchar((x%10)+‘0‘); return; } #define W(x) write(x),putchar(‘ ‘) #define Wl(x) write(x),putchar(‘\n‘) const ll Mod=1000000007; const int N=100005; int T; ll K; ll Qzh[N]; ll dp[N]; int main() { int i,j; R(T); R(K); dp[0]=Qzh[0]=1; for(i=1;i<=100000;i++) { dp[i]+=dp[i-1]; if(i>=K) dp[i]+=dp[i-K]; dp[i]-=(dp[i]>=Mod)?Mod:0; Qzh[i]=Qzh[i-1]+dp[i]; Qzh[i]-=(Qzh[i]>=Mod)?Mod:0; } while(T--) { int l=read(),r=read(); Wl((Qzh[r]-Qzh[l-1]+Mod)%Mod); } return 0; } /* input 3 2 1 3 2 3 4 4 output 6 5 5 */
标签:event 开始 include http 组合数 blank col read lin
原文地址:https://www.cnblogs.com/gaojunonly1/p/10656737.html