题意:给定一个矩阵的第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. Echarts基于动态数据初步使用 及问题 代码记录.

    ECHARTS 插件 基本的动态数据展示(横向图) 下载 echarts.commn.min.js文件 在页面中进行引用, 并为Echarts图形准备一个div盒子 <!-- 引入插件 --&g ...

  2. JAXB - Calling marshal

    Only a handful of source code lines is required to make a JAXB Marshaller object write a document tr ...

  3. 设计模式------STRATEGY(策略模式)

    http://blog.csdn.net/wuzhekai1985/article/details/6665197.仅供参考. 策略模式:实现替换功能,如cache替换算法:当发生Cache缺失时,C ...

  4. centos 6.4 Apache 配置 flv mp4.h264 流媒体拖动

    http://blog.csdn.net/xst686/article/details/9763995 加入流媒体扩展后要重启 httpd flv 流媒体 <textarea style=&qu ...

  5. NOPI读取EXCEL

    public void ReadEXCEL(string filePath) { IWorkbook wk = null; string extension = System.IO.Path.GetE ...

  6. extern int a[] VS extern int *a

    array VS pointer 参考: 1.Extern using pointer instead of array array is not pointer 2.extern array que ...

  7. strcpy(),string使用问题

    两个CString,把一个赋值给另外一个,用strncpy出现问题,直接=赋值正确了,不知道为什么?

  8. java中instanceof和getClass()的作用

    初学者难免有点混淆java中instanceof和getClass()的作用,  下面就来一一讲解. 父类A: class A { } 子类B: class B extends A { }  构造对象 ...

  9. Chrome 建立SOCKS5代理

    前提是putty已经在7090端口和远程服务器建立隧道. 假设你的chrome浏览器位于"C:\Program Files (x86)\Google\Chrome\Application\c ...

  10. Java知识总结--CoreJava

    在网上看到的关于Java的知识总结,觉得很受用,分享给大家..... 如果有什么错误,也欢迎指正批评. 1 简述下java基本数据类型及所占位数,java基本数据类型:4类8种 整数类型:byte(1 ...