[Jzoj 4709]. 【NOIP2016提高A组模拟8.17】Matrix

Description
这里写图片描述

Input

这里写图片描述

Sample Input
4 3 5
4 1 7 3
4 7 4 8
Output
这里写图片描述

Sample Output
59716

The Solution

这是雅礼中学和我们学校的联考题呀。。

上面给的那个dp可以理解成在一个网络上,只能向右,向下走,向下走的话,加上的贡献就要b,向右走的话加上的贡献就要 a。
那么对于l和t,看看这个位置往右往下走多少步就是最后答案中a和b的指数

元素ti对答案的贡献可以拆分成矩阵中从这个点到达F[n,n]也就是右下角的所有路径。
按照上面的方法算贡献。最后计算总和。

可以得到:

Cn22ni2an1bnili+Cn22ni2anibn1ti

组合数为什么这样写呢。
因为对于元素li走到(n,n)的步数有:
打竖走有n-i步,打横走有n-2步,总步数则为2n-i-2步.
而从中选n-2个元素,so….

而对于元素ti同理。

时间复杂度为O(n log n)

考试的时候,因为忘了最后取模,和中间的细节错误而Wa了,只能草草地交了个暴力,水了部分分。比赛后不久发现后就顺利AC了。QAQ。

需改正的地方:

1、打程序要仔细,
2、对拍要认真,
3、注意检查细节

CODE

#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#define fo(i,a,b) for (int i=a;i<=b;i++)
#define fd(i,a,b) for (int i=a;i>=b;i--)
#define mo 1000000007
#define N 100005
using namespace std;
long long F[2*N],mia[N],mib[N],G[N*2],ans=0;
int n,a,b;
long long Calc(int m,int n) 
{
    return F[m]*G[n]%mo*G[m-n]%mo;
}
long long mi(long long x,long long y)
{
    long long z=1;
    while (y)
    {
        if (y&1) z=z*x%mo;
        x=x*x%mo;
        y/=2;
    }
    return z;
}
int main()
{
    freopen("data.in","r",stdin);
    scanf("%d%d%d",&n,&a,&b);
    mia[0]=1,mib[0]=1,F[0]=1;
    fo(i,1,n) 
    {
        mia[i]=(mia[i-1]*(long long)a % mo);
        mib[i]=(mib[i-1]*(long long)b % mo);
    }
    fo(i,1,2*n) F[i]=(F[i-1]*(long long)i)%mo;
    G[2*n]=mi(F[2*n],mo-2);
    long long x=0;
    fd(i,2*n-1,0) G[i]=(G[i+1]*(long long)(i+1))%mo;
    fo(i,1,n) 
    {
        scanf("%lld",&x);
        if (i!=1) (ans=ans+mia[n-1]*mib[n-i]%mo*Calc(2*n-i-2,n-2)%mo*x%mo)%mo;
    }
    fo(i,1,n) 
    {
        scanf("%lld",&x);
        if (i!=1) (ans=ans+mib[n-1]*mia[n-i]%mo*Calc(2*n-i-2,n-2)%mo*x%mo)%mo;
    }
    printf("%lld",ans%mo);
    return 0;
} 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值