zoukankan      html  css  js  c++  java
  • HDU 5015 233Matrix (构造矩阵)

    233 Matrix

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


    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
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <cstdio>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <cmath>
    #include <stack>
    #define LL long long
    using namespace std;
    const long long MAXN = 15;
    const long long mod = 10000007;
    struct Matrix
    {
        long long mat[MAXN][MAXN], n;
        Matrix(){memset(mat, 0, sizeof(mat));}
        Matrix operator * (Matrix & rhs)
        {
            Matrix res; res.n = n;
            for(long long i=1;i<=n;i++)
            {
                for(long long j=1;j<=n;j++)
                {
                    for(long long k=1;k<=n;k++)
                    {
                        (res.mat[i][j] += (mat[i][k] * rhs.mat[k][j]) % mod) %= mod;
                    }
                }
            }
            return res;
        }
    };
    Matrix pow_mod(Matrix a, long long b)
    {
        Matrix res; res.n = a.n;
        for(long long i=1;i<=a.n;i++) res.mat[i][i] = 1;
        while(b)
        {
            if(b & 1) res = res * a;
            a = a * a;
            b >>= 1;
        }
        return res;
    }
    long long a[MAXN], n, m;
    int main()
    {
        while(scanf("%I64d%I64d", &n, &m)!=EOF)
        {
            for(long long i=1;i<=n;i++) scanf("%I64d", &a[i]);
            Matrix ans; ans.n = n + 2;
            for(long long i=1;i<=n + 1;i++)
            {
                ans.mat[i][1] = 10;
                for(long long j=2;j<=i;j++)
                {
                    ans.mat[i][j] = 1;
                }
            }
            for(long long i=1;i<=n+1;i++) ans.mat[n+2][i] = 0;
            for(long long i=1;i<=n+2;i++) ans.mat[i][n+2] = 1;
            ans = pow_mod(ans, m);
         /*   for(long long i=1;i<=n+2;i++)
            {
                for(long long j=1;j<=n+2;j++)
                    cout << ans.mat[i][j] << ' ';
                cout <<endl;
            }*/
            a[0] = 23, a[n+1] = 3;
            long long rs = 0;
            for(long long i=1;i<=n+2;i++) (rs += a[i-1] * ans.mat[n+1][i]) %= mod;
            printf("%I64d
    ", rs);
        }
        return 0;
    }


  • 相关阅读:
    YZR.Data 事务处理(Tranaction)
    啊Ran讲微信开发(.net) :公众号(服务号)+自定义服务器(OAuth授权登录)
    啊Ran讲微信开发(.net) 目录结构
    啊Ran讲微信开发(.net) :公众号(订阅号)+自定义服务器(自定义菜单)
    js和jQuery的总结
    Javascript重要解析
    IntelliJ-项目配置,解决no artifacts的warnings
    农夫过河问题(java版)
    redis安装常见问题
    idea 项目中 maven 编译出错Fatal error compiling: 无效的目标发行版: 1.8 -> [Help 1] 解决方法
  • 原文地址:https://www.cnblogs.com/yjbjingcha/p/6913717.html
Copyright © 2011-2022 走看看