先贴四份矩阵快速幂的模板:http://www.cnblogs.com/shangyu/p/3620803.html

http://www.cppblog.com/acronix/archive/2010/08/23/124470.aspx?opt=admin

http://www.cnblogs.com/vongang/archive/2012/04/01/2429015.html

http://www.cnblogs.com/yan-boy/archive/2012/11/29/2795294.html

233 Matrix

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

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

 
Source
 
Recommend
hujie   |   We have carefully selected several similar problems for you:  5017 5016 5014 5013 5012 

题解1:http://www.cnblogs.com/whatbeg/p/3971994.html

题解2:http://blog.csdn.net/u013368721/article/details/39271565

题目分析:矩阵快速幂,构建一个如下的矩阵即可:

  1. n+2行的矩阵
  2. --                      --   --  --
  3. | 1  1  1  1  1  1  1  0 |   | a1 |
  4. | 0  1  1  1  1  1  1  0 |   | a2 |
  5. | 0  0  1  1  1  1  1  0 |   | a3 |
  6. | 0  0  0  1  1  1  1  0 |   | a4 |
  7. | 0  0  0  0  1  1  1  0 | * | a5 |
  8. | 0  0  0  0  0  1  1  0 |   | an |
  9. |  - - - - - - - - - - - |   |    |
  10. | 0  0  0  0  0  0 10  1 |   | 233|
  11. | 0  0  0  0  0  0  0  1 |   | 3  |
  12. --                      --   --  --
 #include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
#include<string> #define N 15
#define M 15
#define mod 10000007
#define p 10000007
#define mod2 100000000
#define ll long long
#define LL long long
#define maxi(a,b) (a)>(b)? (a) : (b)
#define mini(a,b) (a)<(b)? (a) : (b) using namespace std; ll nn,m;
ll n;
ll x[];
//ll ans; struct Mat
{
ll mat[N][N];
}; Mat e,f,g;
Mat operator * (Mat a,Mat b)
{
Mat c;
memset(c.mat,,sizeof(c.mat));
ll i,j,k;
for(k = ; k < n ; k++)
{
for(i = ; i < n ;i++)
{
if(a.mat[i][k]==) continue;//优化
for(j = ;j < n ;j++)
{
if(b.mat[k][j]==) continue;//优化
c.mat[i][j] = (c.mat[i][j]+(a.mat[i][k]*b.mat[k][j])%mod)%mod;
}
}
}
return c;
}
Mat operator ^(Mat a,ll k)
{
Mat c;
ll i,j;
for(i = ; i < n ;i++)
for(j = ; j < n ;j++)
c.mat[i][j] = (i==j);
for(; k ;k >>= )
{
if(k&) c = c*a;
a = a*a;
}
return c;
} void ini()
{
ll i,j;
for(i=;i<=nn;i++){
scanf("%I64d\n",&x[i]);
}
memset(e.mat,,sizeof(e.mat));
memset(f.mat,,sizeof(f.mat));
e.mat[][]=;
e.mat[][]=;
e.mat[][]=+x[];
for(i=;i<=nn;i++){
e.mat[][i+]=e.mat[][i]+x[i];
}
for(j=;j<nn+;j++){
if(j!=){
f.mat[][j]=;
}
f.mat[][j]=;
}
for(i=;i<nn+;i++){
for(j=i;j<nn+;j++){
f.mat[i][j]=;
}
}
n=nn+;
} void solve()
{
if(m>){
g= e* (f^(m-) );
}
else{
g.mat[][nn+]=e.mat[][nn+];
}
} void out()
{
printf("%I64d\n",g.mat[][nn+]);
} int main()
{
// freopen("data.in","r",stdin);
// freopen("data.out","w",stdout);
//scanf("%d",&T);
//for(int cnt=1;cnt<=T;cnt++)
// while(T--)
while(scanf("%I64d%I64d",&nn,&m)!=EOF)
{
ini();
solve();
out();
} return ;
}

最新文章

  1. ArcGIS Engine开发之地图文档保存
  2. C# 线程通信 一
  3. 新建maven项目
  4. AutoCompleteTextView不能使用的问题
  5. chrome启用本地文件
  6. 面试(3)-java-se-java中的匿名内部类总结
  7. C#创建对象时各种初始化属性、字段的方式的执行顺序
  8. Python学习之MySQLdb模块
  9. [小知识点] react 性能
  10. Django(九)admin相关知识
  11. Django的rest_framework认证组件之局部设置源码解析
  12. 使用Windows的mstsc远程桌面连接到Ubuntu图形界面(AWS上安装的Ubuntu系统)
  13. Swap 分区的2种方式 详解与例子
  14. GitHub 简单用法
  15. pycharm中查找替换妙用
  16. 制作做最小的fedora、ubuntu , jeos系统
  17. vue兄弟组件传递数据
  18. Vue 页面15分钟无操作时返回首页
  19. 用java在客户端读取mongodb中的数据并发送至服务器
  20. MvvmLight框架使用入门(二)

热门文章

  1. pytorch中的view
  2. jquery 获得某一组name的id并合并
  3. fckeditor的实例
  4. 洛谷 P1663 山
  5. nginx 无法加载css/js图片等文件 404 not fund
  6. SpringMVC里静态网页不能加载到.js .css文件的问题
  7. dbfread报错ValueError错误解决方法
  8. 简单几点让你快速了解python是什么
  9. LeetCode(114) Flatten Binary Tree to Linked List
  10. C#中何时使用dynamic