hdu5015 233 Matrix 西安网络赛I题 构造矩阵

本文探讨了如何使用矩阵快速幂解决特定形式的233矩阵问题,详细解释了矩阵构造、快速幂算法及其应用,通过实例演示了解决过程。
部署运行你感兴趣的模型镜像

233 Matrix

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 409    Accepted Submission(s): 273


Problem Description
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?
 

Input
There 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).
 

Output
For 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
Hint

  一直都不太会矩阵的题,部长说一般都是先构造一列,然后乘个矩阵可以得到第二列,以此类推。。。找出这样的矩阵再用矩阵快速幂就行了。

  这题可以发现每个数等于前一列行小于等于这一行的所有数相加,再加上233333那个东西。

  设矩阵B,n+2行:

  a1

  a2

  a3

  ..

  233

  3

矩阵A,n+2行:

  1 0 0  ...1 0

  1 1 0 0..1 0

  1 1 1 0 .1 0 

  1 1 1 1. 1 0

  0 0 0 0..10 0

  0 0 0 0 ..0 1

最后答案是A^M * B,乘完之后第N行的数。

#include<iostream>
#include<queue>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<algorithm>
#define INF 0x3f3f3f3f
#define eps 1e-9
#define MAXN 15
#define MAXM 2000010
#define MAXNODE 105
#define MOD 10000007
#define SIGMA_SIZE 4
typedef long long LL;
using namespace std;
LL N,M,B[MAXN];
struct Mat{
    LL mat[MAXN][MAXN];
    Mat(){
        memset(mat,0,sizeof(mat));
    }
}A;
Mat operator * (Mat a,Mat b){
    int i,j,k;
    Mat ret;
    for(int k=0;k<=N+1;k++)
        for(int i=0;i<=N+1;i++){
            if(!a.mat[i][k]) continue;
            for(int j=0;j<=N+1;j++) ret.mat[i][j]=(ret.mat[i][j]+a.mat[i][k]*b.mat[k][j])%MOD;
        }
    return ret;
}
Mat operator ^ (Mat a,int n){
    Mat ret,t=a;
    for(int i=0;i<=N+1;i++)
        for(int j=0;j<=N+1;j++) ret.mat[i][j]=(i==j);
    while(n){
        if(n&1) ret=ret*t;
        t=t*t;
        n>>=1;
    }
    return ret;
}
void get_A(){
    memset(A.mat,0,sizeof(A.mat));
    for(int i=0;i<N;i++)
        for(int j=0;j<=i;j++) A.mat[i][j]=1;
    for(int i=0;i<N;i++) A.mat[i][N]=1;
    A.mat[N][N]=10;
    A.mat[N][N+1]=A.mat[N+1][N+1]=1;
}
int main(){
    freopen("in.txt","r",stdin);
    while(scanf("%I64d%I64d",&N,&M)!=EOF){
        for(int i=0;i<N;i++) scanf("%I64d",&B[i]);
        B[N]=233;
        B[N+1]=3;
        get_A();
        A=A^M;
        LL ans=0;
        for(int i=0;i<=N+1;i++) ans=(ans+A.mat[N-1][i]*B[i])%MOD;
        printf("%I64d\n",ans);
    }
    return 0;
}


您可能感兴趣的与本文相关的镜像

GPT-SoVITS

GPT-SoVITS

AI应用

GPT-SoVITS 是一个开源的文本到语音(TTS)和语音转换模型,它结合了 GPT 的生成能力和 SoVITS 的语音转换技术。该项目以其强大的声音克隆能力而闻名,仅需少量语音样本(如5秒)即可实现高质量的即时语音合成,也可通过更长的音频(如1分钟)进行微调以获得更逼真的效果

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值