Description
Solution
考虑到每一个块的值都是由它的(左块a+右块*b),如果保留块的编号,推到右下角后发现都是由第一行或第一列的块乘上a的若干次方和b的若干次方。但是这样子推出来的信息并不能直接计算,但是却给我们提供了一条思路:计算第一行或第一列的数对答案的贡献。由推出的算式可以发现,对于一个块,向下走一格就*b,向右走一格就*a。计算总和,得到 Cn−22n−i−2 an−i bn−1 或 Cn−22n−i−2 an−1 * bn−i 。
Code
const mo=1000000007;
var
c,ni:array[0..200000] of int64;
x,y:array[1..100000] of int64;
n,i,j,a,b:longint;
ans,t:int64;
function ksm(x,y:longint):int64;
begin
if y=0 then exit(1);
if y=1 then exit(x);
if y mod 2=0 then exit(sqr(ksm(x,y div 2) mod mo)mod mo)
else exit((ksm(x,y-1)*x)mod mo);
end;
function jc(n,m:longint):int64;
begin
jc:=c[m];
t:=ni[n];
jc:=(jc*t)mod mo;
t:=ni[m-n];
jc:=(jc*t)mod mo;
exit(jc);
end;
begin
readln(n,a,b);
c[0]:=1;ni[0]:=ksm(c[0],mo-2);
for i:=1 to 2*n do
begin
c[i]:=(c[i-1]*i)mod mo;
ni[i]:=ksm(c[i],mo-2);
end;
for i:=1 to n do read(x[i]);
for i:=1 to n do read(y[i]);
if n=1 then
begin
writeln(x[1]);
exit;
end;
ans:=0;
for i:=2 to n do
ans:=(ans+(((jc(n-2,2*n-i-2)*ksm(a,n-i))mod mo*ksm(b,n-1))mod mo*y[i])mod mo)mod mo;
for i:=2 to n do
ans:=(ans+(((jc(n-2,2*n-i-2)*ksm(a,n-1))mod mo*ksm(b,n-i))mod mo*x[i])mod mo)mod mo;
writeln(ans);
end.