# [bzoj5015][Snoi2017]礼物

N≤10^18,K≤10

#include<iostream>
#include<cstring>
#include<cstdio>
#define mod 1000000007
using namespace std;
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int k,C[15][15];long long n;
struct Matrix
{
int s[12][12];
Matrix(){memset(s,0,sizeof(s));}
Matrix operator * (const Matrix&b)
{
Matrix c;
for(int i=0;i<=k+1;++i)
for(int j=0;j<=k+1;++j)
for(int K=0;K<=k+1;++K)
c.s[i][j]=(c.s[i][j]+1LL*s[i][K]*b.s[K][j])%mod;
return c;
}
void print()
{
for(int i=0;i<=k+1;++i,puts(""))
for(int j=0;j<=k+1;++j)
printf("%d ",s[i][j]);
}
}A,B,c,d;

int Solve(long long N)
{
A=c;B=d;
for(;N;N>>=1,A=A*A) if(N&1) B=A*B;
return B.s[k+1][0];
}

int main()
{
for(int i=0;i<=12;++i) C[i][0]=1;
for(int i=1;i<=12;++i)for(int j=1;j<=i;++j) C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
cin>>n>>k;
A.s[k+1][k+1]=2;A.s[k+1][k]=1;A.s[0][0]=1;
for(int i=0;i<=k;++i)
{
B.s[i][0]=1;
for(int j=0;j<=i;++j)
A.s[i][j]=C[i][i-j];
}
c=A;d=B;
printf("%d\n",(Solve(n)-Solve(n-1)+mod)%mod);
return 0;
}
posted @ 2017-09-06 16:43  FallDream  阅读(254)  评论(0编辑  收藏  举报