NOIP 模拟 $13\; \text{工业题}$
题解
本题不用什么推式子,找规律(而且也找不出来)
可以将整个式子看成一个 \(n×m\) 矩阵
考虑 \(f_{i,j}\),它向右走一步给出 \(f_{i,j}×a\) 的贡献,向下走一步给出 \(f_{i,j}×b\) 的贡献,那么它到 \(f_{n,m}\) 给出 \(f_{i,j}×a^{m-j}+f_{i,j}×b^{n-i}\) 的贡献
但是,它到终点会有不同的走法,这个用组合数解即可,注意对于 \(f_{i,0}\) 它第一步只能向右走,因为向下的数是确定的。其它同理
预处理出阶乘,逆元和 \(a,b\) 的幂,按上述求解即可
Code
#include<bits/stdc++.h>
#define ri register signed
#define p(i) ++i
using namespace std;
namespace IO{
char buf[1<<21],*p1=buf,*p2=buf;
#define gc() p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++
template<typename T>inline void read(T &x) {
ri f=1;x=0;register char ch=gc();
while(ch<'0'||ch>'9') {if (ch=='-') f=0;ch=gc();}
while(ch>='0'&&ch<='9') {x=(x<<1)+(x<<3)+(ch^48);ch=gc();}
x=f?x:-x;
}
}
using IO::read;
namespace nanfeng{
#define cmax(x,y) ((x)>(y)?(x):(y))
#define cmin(x,y) ((x)>(y)?(y):(x))
#define FI FILE *IN
#define FO FILE *OUT
typedef long long ll;
static const int MOD=998244353,N=3e5+7;
ll numx[N],numy[N],cma[N],cmb[N],frac[N<<1],inv[N<<1],a,b,ans;
int n,m,mx;
inline void init(int x) {
int tmp=x<<1;
inv[0]=inv[1]=frac[1]=1;
for (ri i(2);i<=tmp;p(i)) frac[i]=frac[i-1]*i%MOD;
for (ri i(2);i<=tmp;p(i)) inv[i]=(MOD-MOD/i)*inv[MOD%i]%MOD;
for (ri i(2);i<=tmp;p(i)) (inv[i]*=inv[i-1])%=MOD;
}
inline ll C(int a,int b) {return (!a&&!b)?1:frac[a]*inv[a-b]%MOD*inv[b]%MOD;}
inline int main() {
// FI=freopen("nanfeng.in","r",stdin);
// FO=freopen("nanfeng.out","w",stdout);
read(n),read(m),read(a),read(b);
mx=cmax(n,m);
init(mx);
cma[0]=cmb[0]=1;
a%=MOD,b%=MOD;
for (ri i(1);i<=mx;p(i)) cma[i]=cma[i-1]*a%MOD,cmb[i]=cmb[i-1]*b%MOD;
for (ri i(1);i<=n;p(i)) read(numx[i]),numx[i]%=MOD;
for (ri i(1);i<=m;p(i)) read(numy[i]),numy[i]%=MOD;
for (ri i(1);i<=n;p(i)) (ans+=numx[i]*C(m+n-i-1,m-1)%MOD*cma[m]%MOD*cmb[n-i]%MOD)%=MOD;
for (ri i(1);i<=m;p(i)) (ans+=numy[i]*C(n+m-i-1,n-1)%MOD*cma[m-i]%MOD*cmb[n]%MOD)%=MOD;
printf("%lld\n",ans);
return 0;
}
}
int main() {return nanfeng::main();}
此题较坑,他输入的 \(a,b,f_{i,0},f_{0,i}\) 均为 long long 范围,所以输入完后要先取模。