题意:给定一个矩阵的第0列的第1到n个数,第一行第1个数开始每个数分别为233, 2333........,求第n行的第m个数。

分析:

其实也没那么难,自己想了半天还没往对的方向想,m最大1e9,应该立即想到要用到快速幂,关键在于递推矩阵。

递推矩阵的作用是依次算出每一列,第1列第一个数233是前一列的23*10+3,将前一列增加一个元素[3, 23, a1, a2,....an],然后第一列第一个数为3,对应向量[1, 0, 0, 0.....0],233对应向量[1, 10, 0, .....0],下一个的数对应[1, 10, 1.....0], 接下来每个数对应的向量是上一个数的向量最后一个1元素后面增加1个1,这样将n+2个向量构成一个(n+2)*(n+2)的矩阵,需要求m次该矩阵,然后和[3, 23, a1, a2, .....an]相乘。

代码:

 #include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#define inf 0x0f0f0f0f
#define pb push_back
#define bug(x) printf("line %d: >>>>>>>>>>>>>>>\n", (x));
#define in freopen("F:\\code\\data\\data.txt", "r", stdin);
#define out freopen("F:\\code\\data\\data_out.txt", "w", stdout); #define SZ(x) ((int)x.size())
#define lson rt<<1, l, m
#define rson rt<<1|1, m+1, r
using namespace std; typedef long long LL;
const int maxn = ;
const int M = ; struct Matrix
{
int n, m;
LL a[maxn][maxn];
Matrix(int n, int m)
{
this->n = n;
this->m = m;
for(int i = ; i < maxn; i++)
for(int j = ; j < maxn; j++)
a[i][j] = ;
}
Matrix operator * (const Matrix &o)const
{
Matrix c(n, o.m);
for(int i = ; i < n; i++)
for(int j = ; j < o.m; j++)
{
for(int k = ; k < m; k++)
c.a[i][j] = (c.a[i][j]+a[i][k]*o.a[k][j]%M)%M;
}
return c;
}
};
int n, m;
int main()
{ while(scanf("%d%d", &n, &m) == )
{
Matrix f(n+, n+), res(n+, n+), tmp(n+, );
tmp.a[][] = ;
tmp.a[][] = ;
for(int i = ; i <= n+; i++)
scanf("%I64d", &tmp.a[i][]);
for(int i = ; i <= n+; i++)
for(int j = ; j <= n+; j++)
{
if(i == )
{
f.a[i][] = ;
break;
}
else if(i == )
{
f.a[i][] = ;
f.a[i][] = ;
break;
}
else
{
if(j < i)
f.a[i][j] = f.a[i-][j];
else if(j == i) f.a[i][j] = ;
}
}
for(int i = ; i < n+; i++)
for(int j = ; j < n+; j++)
if(i == j)
res.a[i][j] = ;
while(m)
{
if(m&)
res = res*f;
f = f*f;
m >>= ;
}
tmp = res*tmp;
printf("%I64d\n", tmp.a[n+][]);
}
return ;
}

HDU 5015 233 Matrix的更多相关文章

  1. HDU - 5015 233 Matrix(杨辉三角/前缀+矩阵快速幂)

    233 Matrix In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23 ...

  2. HDU 5015 233 Matrix(网络赛1009) 矩阵快速幂

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

  3. hdu 5015 233 Matrix (矩阵高速幂)

    233 Matrix Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Tota ...

  4. HDU - 5015 233 Matrix (矩阵快速幂)

    In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23333, or 233 ...

  5. hdu 5015 233 Matrix(构造矩阵)

    http://acm.hdu.edu.cn/showproblem.php?pid=5015 由于是个二维的递推式,当时没有想到能够这样构造矩阵.从列上看,当前这一列都是由前一列递推得到.依据这一点来 ...

  6. HDU 5015 233 Matrix --矩阵快速幂

    题意:给出矩阵的第0行(233,2333,23333,...)和第0列a1,a2,...an(n<=10,m<=10^9),给出式子: A[i][j] = A[i-1][j] + A[i] ...

  7. hdu 5015 233矩阵快速幂

    http://acm.hdu.edu.cn/showproblem.php?pid=5015 需要构造一个 n+2 维的矩阵. 就是要增加一维去维护2333这样的序列. 可以发现 2333 = 233 ...

  8. HDU [P5015] 233 Matrix

    矩阵快速幂 按列递推 #include <iostream> #include <cstdio> #include <cstdlib> #include <a ...

  9. Spring-1-I 233 Matrix(HDU 5015)解题报告及测试数据

    233 Matrix Time Limit:5000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Descript ...

随机推荐

  1. SSM成功了

  2. ASP长文章分页的两个方法,函数

    '按标识手动分页 function manualPage(str) pages=request.QueryString("page") contentstr=split(str,& ...

  3. apache ambari web页面无法访问解决办法

    ambari-server启动成功,但是页面无法访问 作者:Bo liang链接:http://www.zhihu.com/question/34405898/answer/115001510来源:知 ...

  4. 转载---SQL Server XML基础学习之<7>--XML modify() 方法对 XML 数据中插入、更新或删除

    /*------------------------------------------------------------------------------+ #| = : = : = : = : ...

  5. C语言对文件的相关命令

    fopen(文件名,使用文件的方式):打开数据文件 fclose(FILE *fp):关闭数据文件 feof(FILE *fp):是判断是否到fp的结尾 fputc(char ch,FILE *fp) ...

  6. The method getContextPath() is undefined for the type ServletContext

    我出错时,到网上说得是版本问题,我找到对应的包javax-servlet5.1.12.jar,把它删了,居然不报错了,原来是和包servlet-2_5-api.jar冲突了

  7. Cabarc Overview (Microsoft TechNet)

    Original Link:  Cabarc Overview Applies To: Windows Server 2003, Windows Server 2003 R2, Windows Ser ...

  8. VMware10.0.4下 CentOS 6.5 cmake安装 MySQL 5.5.32

    一.准备工作 1.1.创建 zhuzz/tools目录 [root@localhost ~]# mkdir -p /home/zhuzz/tools [root@localhost ~]# cd /h ...

  9. PHPStrom 使用技巧以及基本设置教程【更新完结】

    本博文由北京乐学一百在线教育科技有限公司平台开发组成员提供,在此表示感谢,截图来源于Tower,热力推荐的一款不错的办公工具. 1.SVN链接上的条件下,修改子文件,父文件夹以及祖辈文件夹变色设置:​ ...

  10. rpm方式安装gcc缺少依赖项的解决方法

    使用rpm方式安装gcc时,有时会报缺少依赖项: libmpfr.so.1 is needed by cpp-4.4.4-13.el6.i686 libppl.so.7 is needed by cl ...