2014西安網路賽1009||hdu5015 矩陣
http://acm.hdu.edu.cn/showproblem.php?pid=5015
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).
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
![](https://i.iter01.com/images/b0c9a37d764eebf338fc54e8ef8dc3e3ec07d7374d103eaa9ce38b5dd5c5ecff.jpg)
Hint
![](https://i.iter01.com/images/b0c9a37d764eebf338fc54e8ef8dc3e3ec07d7374d103eaa9ce38b5dd5c5ecff.jpg)
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
const int N=10005;
const int MOD=10000007;
int n;
LL m,a[20];
struct Matrix
{
LL m[15][15];
};
Matrix I;
Matrix mult(Matrix a,Matrix b)
{
Matrix 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])%MOD;
c.m[i][j]%=MOD;
}
return c;
}
Matrix quick_mod(Matrix a,LL n)
{
Matrix c=I;
while(n)
{
if(n&1)
c=mult(c,a);
n>>=1;
a=mult(a,a);
}
return c;
}
int main()
{
while(~scanf("%d%I64d",&n,&m))
{
a[0]=3;
a[1]=23;
for(int i=2;i<n+2;i++)
scanf("%I64d",&a[i]);
for(int i=0;i<n+2;i++)
for(int j=0;j<n+2;j++)
if(i==j)
I.m[i][j]=1;
else
I.m[i][j]=0;
/* for(int i=0;i<n+2;i++)
{
for(int j=0;j<n+2;j++)
printf("%I64d ",I.m[i][j]);
printf("\n");
}*/
Matrix A;
for(int i=0;i<n+2;i++)
for(int j=0;j<n+2;j++)
if(i>=j)
A.m[i][j]=1;
else
A.m[i][j]=0;
for(int i=1;i<n+2;i++)
A.m[i][1]=10;
LL ans=0;
Matrix B=quick_mod(A,m);
/*for(int i=0;i<n+2;i++)
{
for(int j=0;j<n+2;j++)
printf("%I64d ",B.m[i][j]);
printf("\n");
}*/
for(int i=0;i<n+2;i++)
ans=(ans+B.m[n+1][i]*a[i]%MOD)%MOD;
printf("%I64d\n",ans);
}
return 0;
}
相關文章
- 2024矩陣杯初賽矩陣
- 中新賽克網路洞察矩陣,安全及可視的基礎設施矩陣
- 田忌賽馬博弈矩陣分析矩陣
- 矩陣中的路徑矩陣
- 巨大的矩陣(矩陣加速)矩陣
- 鄰接矩陣、度矩陣矩陣
- 奇異矩陣,非奇異矩陣,偽逆矩陣矩陣
- 社交網路分析的 R 基礎:(三)向量、矩陣與列表矩陣
- 資料結構:陣列,稀疏矩陣,矩陣的壓縮。應用:矩陣的轉置,矩陣相乘資料結構陣列矩陣
- 矩陣矩陣
- JZ-065-矩陣中的路徑矩陣
- 求任意矩陣的伴隨矩陣矩陣
- 2014中國網路效能報告
- 矩陣和陣列矩陣陣列
- 理解矩陣矩陣
- 海浪矩陣矩陣
- 矩陣相乘矩陣
- 稀疏矩陣矩陣
- 螺旋矩陣矩陣
- 矩陣乘法矩陣
- 8.6 矩陣?矩陣
- 找矩陣矩陣
- 矩陣分解矩陣
- 快手矩陣管理平臺,矩陣管理有方法矩陣
- 西安網際網路知名度如何(CRMEB系統)
- 機器學習中的矩陣向量求導(五) 矩陣對矩陣的求導機器學習矩陣求導
- 矩陣:如何使用矩陣操作進行 PageRank 計算?矩陣
- 演算法學習:矩陣快速冪/矩陣加速演算法矩陣
- 高斯消除矩陣矩陣
- 矩陣求導矩陣求導
- 置換矩陣矩陣
- 視訊矩陣矩陣
- 矩陣樹定理矩陣
- leetcode:螺旋矩陣LeetCode矩陣
- 矩陣置0矩陣
- 雅可比矩陣矩陣
- 隨機矩陣隨機矩陣
- 矩陣計算矩陣
- 矩陣求逆矩陣