设为首页 加入收藏

TOP

hdu 5015 233 Matrix (矩阵快速幂)
2015-07-20 17:39:10 来源: 作者: 【 】 浏览:2
Tags:hdu 5015 233 Matrix 矩阵 快速

233 Matrix

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


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 a 0,1 = 233,a 0,2 = 2333,a 0,3 = 23333...) Besides, in 233 matrix, we got a i,j = a i-1,j +a i,j-1( i,j ≠ 0). Now you have known a 1,0,a 2,0,...,a n,0, could you tell me a n,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 ≤ 10 9). The second line contains n integers, a 1,0,a 2,0,...,a n,0(0 ≤ a i,0 < 2 31).
Output For each case, output a n,m mod 10000007.
Sample Input
1 1
1
2 2
0 0
3 7
23 47 16

Sample Output
234
2799
72937

Hint

  
\
<??http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vcHJlPgoKPGJyPgo8cD48L3A+CjxwPsu8wrejujwvcD4KPHA+PC9wPgo8cD4KtdrSu8HQ1KrL2M6qo7o8L3A+CjxwPgowPC9wPgo8cD4KYTE8L3A+CjxwPgphMjwvcD4KPHA+CjwvcD4KPHA+CmEzPC9wPgo8cD4KYTQ8L3A+Ctequ6/OqqO6CjxwPgoyMzwvcD4KPHA+CjwvcD4KPHA+CmExPC9wPgo8cD4KYTI8L3A+CjxwPgo8L3A+CjxwPgphMzwvcD4KPHA+CmE0PC9wPgo8cD4zPC9wPgo8cD7U8rXatv7B0M6qo7o8L3A+CjxwPjIzKjEwJiM0MzszPC9wPgo8cD4KMjMqMTAmIzQzOzMmIzQzO2ExPC9wPgo8cD4KMjMqMTAmIzQzOzMmIzQzO2ExJiM0MzthMjwvcD4KPHA+CjwvcD4KPHA+CjIzKjEwJiM0MzszJiM0MzthMSYjNDM7YTImIzQzO2EzPC9wPgo8cD4KMjMqMTAmIzQzOzMmIzQzO2ExJiM0MzthMiYjNDM7YTMmIzQzO2E0PC9wPgo8cD4zPC9wPgq4+b7dx7C688G9wdC1xLXdzca52M+1o6zT0LXIyr2/ybXDvtjV80G1xNSqy9jOqqO6PGltZyBzcmM9"https://www.cppentry.com/upload_files/article/49/1_h4cy5__.jpg" alt="\">

#include"iostream"
#include"stdio.h"
#include"string.h"
#include"algorithm"
#include"queue"
#include"vector"
using namespace std;
#define N 15
#define LL __int64
const int mod=10000007;
int n;
int b[N];
struct Mat
{
    LL mat[N][N];
}a,ans;
Mat operator*(Mat a,Mat b)
{
    int i,j,k;
    Mat c;
    memset(c.mat,0,sizeof(c.mat));
    for(i=0; i<=n+1; i++)
    {
        for(j=0; j<=n+1; j++)
        {
            c.mat[i][j]=0;
            for(k=0; k<=n+1; k++)
            {
                if(a.mat[i][k]&&b.mat[k][j])
                {
                    c.mat[i][j]+=a.mat[i][k]*b.mat[k][j];
                    c.mat[i][j]%=mod;
                }
            }
        }
    }
    return c;
}
void mult(int k)
{
    int i;
    memset(ans.mat,0,sizeof(ans.mat));
    for(i=0;i<=n+1;i++)
        ans.mat[i][i]=1;
    while(k)
    {
        if(k&1)
            ans=ans*a;
        k>>=1;
        a=a*a;
    }
}
void inti()
{
    int i,j;
    b[0]=23;
    b[n+1]=3;
    for(i=1; i<=n; i++)
        scanf("%d",&b[i]);
    memset(a.mat,0,sizeof(a.mat));
    for(i=0; i<=n; i++)
    {
        a.mat[i][0]=10;
        a.mat[i][n+1]=1;
    }
    a.mat[n+1][n+1]=1;
    for(i=1; i
   
    



】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇POJ 3233 Matrix Power Series(矩.. 下一篇Effective C++:条款41:了解隐式..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·数据库:推荐几款 Re (2025-12-25 12:17:11)
·如何最简单、通俗地 (2025-12-25 12:17:09)
·什么是Redis?为什么 (2025-12-25 12:17:06)
·对于一个想入坑Linux (2025-12-25 11:49:07)
·Linux 怎么读? (2025-12-25 11:49:04)