ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

2020 BIT冬训-二分三分快速幂矩阵 K - 233 Matrix HDU - 5015

2021-02-17 19:34:09  阅读:219  来源: 互联网

标签:... HDU 2333 Matrix ai 5015 a0 matrix 233


In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23333, or 233333 ... in the same meaning. And here is the question: Suppose we have a matrix called 233 matrix. In the first line, it would be 233, 2333, 23333... (it means a0,1 = 233,a0,2 = 2333,a0,3 = 23333...) Besides, in 233 matrix, we got ai,j = ai-1,j +ai,j-1( i,j ≠ 0). Now you have known a1,0,a2,0,...,an,0, could you tell me an,m in the 233 matrix?

InputThere are multiple test cases. Please process till EOF.

For each case, the first line contains two postive integers n,m(n ≤ 10,m ≤ 109). The second line contains n integers, a1,0,a2,0,...,an,0(0 ≤ ai,0 < 231).OutputFor each case, output an,m mod 10000007.Sample Input

1 1
1
2 2
0 0
3 7
23 47 16

Sample Output

234
2799
72937


 

这题的思路依旧是矩阵加速。

下面为题意:

递推关系为ai,j=ai-1,j+ai,j-1。其中a0,1,a0,2等i=0的数为2333…。j=0的数为题目所提供。

任意给一个i,j,求他模10000007后所得的值。

我们可以通过构造矩阵一列一列的求出每列的值。到第j列后求第i行的值即可。

2333……可以通过前一个数*10+3来获得。因此我们的初始矩阵可以加上10和3来运行。

构造的转换矩阵如下:

 

 

AC代码如下:

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
long long n,m,arr[15],arrans[15],out1;
typedef struct mar{
    long long m[15][15];
    void Init(){
        memset(m,0,sizeof(m));
        for(int i=0;i<15;i++)
            m[i][i]=1;
    }
}Mart;
Mart Multi(Mart a,Mart b){
    Mart c;
    for(int i=0;i<n+2;i++)
        for(int j=0;j<n+2;j++){
            c.m[i][j]=0;
            for(int k=0;k<n+2;k++)
                c.m[i][j]+=(a.m[i][k]*b.m[k][j])%10000007;
            c.m[i][j]%=10000007;
        }
    return c;
}
Mart Quick_pow(Mart a,int m){
    Mart ans;
    ans.Init();
    while(m){
        if(m&1)
            ans=Multi(ans,a);
        m>>=1;
        a=Multi(a,a);
    }
    return ans;
}
int main(){
    while(~scanf("%lld%lld",&n,&m)){
        Mart transf;
        arr[0]=23,arr[n+1]=3;
        for(int i=1;i<=n;i++)
            scanf("%lld",&arr[i]);
        for(int i=0;i<n+2;i++)
            for(int j=0;j<n+2;j++){
                if(j==0&&i!=n+1)
                    transf.m[i][j]=10;
                else if((j==n+1)||(i>=j&&i!=n+1))
                    transf.m[i][j]=1;
                else
                    transf.m[i][j]=0;
            }
        Mart ans = Quick_pow(transf,m);
        out1=0;
        for(int i=0;i<n+2;i++)
            out1+=(ans.m[n][i]*arr[i])%10000007;
        out1%=10000007;
        printf("%lld\n",out1);
    }
    
}

 

 

 

 

标签:...,HDU,2333,Matrix,ai,5015,a0,matrix,233
来源: https://www.cnblogs.com/mikku39/p/14409489.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有