题意:给定一个矩阵的第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. ant design 自定义表单验证大全

     需求是 账号名可以是手机号也可以是邮箱 要做手机号和邮箱的验证,官网的那个验证规则不匹配  怎么自定义验证规则?  一:组件部分 <Form horizontal> <Row gu ...

  2. MySQL - 日志管理

    在 MySQL 中,有 4 种不同的日志,分别是错误日志.二进制日志.查询日志和慢查询日志. 错误日志 错误日志记录了 MySQL 启动和停止时以及服务器在运行过程中发生严重错误时的相关信息. 查看错 ...

  3. oc语言学习之基础知识点介绍(四):方法的重写、多态以及self、super的介绍

    一.方法重写 /* 重写:当子类继承了父类的方法时,如果觉得父类的方法不适合,那么可以对这个方法进行重新实现,那么这个就重写. 注意:也就是说,一定只能发生在父类和子类关系中. 然后是子类重新实现父类 ...

  4. oracle-替换 换行符和空格符

    --换行或空格: )), '') --换行及空格: update tableName set columnName= ), ), '')

  5. and or判别

    and 和 or涉及到短路运算,python把0,'',none看做false,其余是true, 对于a and b,若a是true则,返回b,若a是false则返回a(因为a是true还需要判断b, ...

  6. mysql net连接读取结果为乱码 Incorrect string value

    在mysql直接查询中文正常,通过连接到mysql读取中文内容为乱码.同时插入中文内容也失败提示 Incorrect string value: '\xBC\xA4\xB7\xA2\xBF\xB4.. ...

  7. 准备Activiti的开发环境

    1.创建项目

  8. 代码静态分析工具PCLint, Splint

    一.PCLint REFER: 代码静态检查工具PC-Lint运用实践 二.Splint 1.在PC-Linux上安装 ①make error undefined reference toyywrap ...

  9. 避免ajax请求过多,导致内存溢出,请求之后回收资源

    php试题网 http://phpshiti.com/ http://www.jb51.net/article/30458.htm success: function (data, textStatu ...

  10. 快速排序算法 Quick sort

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4046189.html 首先随机选择一个轴,并调整数组内各个数字,使得比轴值大的数在轴的右边, ...