Matrix

Description

这里写图片描述

Solution

考虑到每一个块的值都是由它的(左块a+右块*b),如果保留块的编号,推到右下角后发现都是由第一行或第一列的块乘上a的若干次方和b的若干次方。但是这样子推出来的信息并不能直接计算,但是却给我们提供了一条思路:计算第一行或第一列的数对答案的贡献。由推出的算式可以发现,对于一个块,向下走一格就*b,向右走一格就*a。计算总和,得到 Cn22ni2 ani bn1 Cn22ni2 an1 * bni

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.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值