构造矩阵$y=\begin{bmatrix}B& C& 0& ....& 0& 0& 0& \\ A& B& C& ....& 0& 0& 0& \\ & & & ....& & & & \\ 0& 0& 0& ....& A& B& C& \\ 0& 0& 0& ....& 0& A& B& \end{bmatrix}$
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
inline int read()
{
int x=0; char ch=getchar();
while (ch<‘0‘ || ch>‘9‘) {ch=getchar();}
while (ch>=‘0‘ && ch<=‘9‘) {x=x*10+ch-‘0‘; ch=getchar();}
return x;
}
int N,M,A,B,C,T;
struct MatrixNode{int a[51][51];}x,y;
inline MatrixNode mul(MatrixNode a,MatrixNode b)
{
MatrixNode c;
for (int i=1; i<=N; i++)
for (int j=1; j<=N; j++)
c.a[i][j]=0;
for (int k=1; k<=N; k++)
for (int i=1; i<=N; i++)
if (a.a[i][k])
for (int j=1; j<=N; j++)
if (b.a[k][j])
c.a[i][j]=(c.a[i][j]+(a.a[i][k]*b.a[k][j]))%M;
return c;
}
inline MatrixNode quick_pow(MatrixNode a,int b)
{
MatrixNode re;
for (int i=1; i<=N; i++)
for (int j=1; j<=N; j++)
re.a[i][j]=i==j? 1:0;
for (int i=b; i; i>>=1,a=mul(a,a))
if (i&1) re=mul(re,a);
return re;
}
void Debug(MatrixNode x)
{
puts("start");
for (int i=1; i<=N; i++,puts(""))
for (int j=1; j<=N; j++)
printf("%d ",x.a[i][j]);
puts("end");
}
int main()
{
while (scanf("%d%d%d%d%d%d",&N,&M,&A,&B,&C,&T))
{
if (!(N+M+A+B+C+T)) break;
for (int i=1; i<=N; i++) x.a[1][i]=read();
for (int i=1; i<=N; i++)
for (int j=1; j<=N; j++)
y.a[i][j]=0;
//Debug(x);
for (int i=1; i<=N; i++)
y.a[i][i+1]=A,y.a[i][i]=B,y.a[i][i-1]=C;
//Debug(y);
MatrixNode t=quick_pow(y,T);
//Debug(t);
x=mul(x,t);
printf("%d",x.a[1][1]);
for (int i=2; i<=N; i++) printf(" %d",x.a[1][i]);
puts("");
}
return 0;
}