代码:
1 #include2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 9 #define LL long long10 #define res register int11 12 const int N=100000+5,mod=1e9+7;13 int f[N],n,k;14 15 int main()16 {17 freopen("debug.in","r",stdin);18 freopen("debug.out","w",stdout);19 scanf("%lld %lld",&n,&k);20 f[0]=1;21 for(res i=1 ; i<=n ; i++)22 {23 f[i]=f[i-1];24 if(i>=k) f[i]=(f[i]+f[i-k])%mod;25 else f[i]=(f[i]+1)%mod;26 }27 if(n-2k+1<0) ans=(f[n-k]-1)%mod;28 int ans=(f[n-k]+(LL)k*f[n-2*k+1]%mod-1)%mod;29 printf("%d\n",ans);30 return 0;31 }