给定长度为n的数组a,定义一次操作为:
1. 算出长度为n的数组s,使得si= (a[1] + a[2] + ... + a[i]) mod 1,000,000,007;
2. 执行a = s;
现在问k次操作以后a长什么样
记初始序列为$a_0$, $k$次操作后序列为$a_k$, 有
$egin{equation}
a_k
=egin{bmatrix}
1 & 0 & 0 &cdots &0 &0\
1 & 1 & 0 &cdots &0 &0\
1 & 1 & 1 & cdots & 0 & 0\
vdots & vdots & vdots & ddots & vdots &vdots\
1 & 1 & 1 &cdots &1& 1\
end{bmatrix}^k a_0
end{equation}$
矩阵幂可以化简为
$egin{equation}
egin{bmatrix}
inom{k-1}{0} & 0 & 0 &cdots &0 &0\
inom{k}{1} & inom{k-1}{0} & 0 &cdots &0 &0\
inom{k+1}{2} & inom{k}{1} &inom{k-1}{0} & cdots & 0 & 0\
vdots & vdots & vdots & ddots & vdots &vdots\
inom{k+n-2}{n-1} & inom{k+n-3}{n-2} & inom{k+n-4}{n-3} &cdots &inom{k}{1}& inom{k-1}{0}\
end{bmatrix}
end{equation}$
#include <iostream> #include <sstream> #include <algorithm> #include <cstdio> #include <math.h> #include <set> #include <map> #include <queue> #include <string> #include <string.h> #include <bitset> #define REP(i,a,n) for(int i=a;i<=n;++i) #define PER(i,a,n) for(int i=n;i>=a;--i) #define hr putchar(10) #define pb push_back #define lc (o<<1) #define rc (lc|1) #define mid ((l+r)>>1) #define ls lc,l,mid #define rs rc,mid+1,r #define x first #define y second #define io std::ios::sync_with_stdio(false) #define endl ' ' #define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;}) using namespace std; typedef long long ll; typedef pair<int,int> pii; const int P = 1e9+7, P2 = 998244353, INF = 0x3f3f3f3f; ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;} ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;} ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;} inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;} //head const int N = 2e3+10; int n, k; int a[N], f[N]; int main() { scanf("%d%d", &n, &k); REP(i,1,n) scanf("%d", a+i); f[1] = 1; REP(i,2,n) f[i]=(ll)f[i-1]*(k+i-2)%P*inv(i-1)%P; REP(i,1,n) { int ans = 0; REP(j,1,i) ans = (ans+(ll)f[i-j+1]*a[j])%P; printf("%d ", ans); } hr; }