A Simple Math Problem

【题目链接】A Simple Math Problem

【题目类型】矩阵快速幂

&题解:

这是一个模板题,也算是入门了吧. 推荐一个博客:点这里 跟着这个刷,应该就可以了

&代码:

#include <cstdio>
#include <iostream>
#include <set>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
using namespace std;
#define INF 0x3f3f3f3f
using ll=long long;
typedef vector<ll> vec;
typedef vector<vec> mat;
const int maxn= 10 +9;
ll k,m,a[maxn];
mat mul(mat &A,mat &B)
{
mat C(A.size(),vec(B[0].size()));
for(int i=0;i<A.size();i++)
for(int k=0;k<B.size();k++)
for(int j=0;j<B[0].size();j++){
C[i][j]=(C[i][j]+A[i][k]*B[k][j])%m;
}
return C;
} mat bin_pow(mat A,ll n)
{
int si=A.size();
mat B(si,vec(si));
for(int i=0;i<si;i++)
B[i][i]=1;
while(n>0){
if(n&1)
B=mul(B,A);
A=mul(A,A);
n>>=1;
}
return B;
}
int main()
{
freopen("E:1.txt","r",stdin);
while(cin>>k>>m){
for(int i=0;i<10;i++)
cin>>a[i]; mat A(10,vec(10));
for(int i=0;i<10;i++){
A[0][i]=a[i];
if(i>0) A[i][i-1]=1;
}
if(k<10) cout<<k<<endl;
else{
A=bin_pow(A,k);
// for(auto i:A){
// for(auto j:i)
// cout<<j<<" ";
// cout<<endl;
// }
ll ans=0;
for(int i=0;i<10;i++){
ans=(ans+A[9][i]*(9-i))%m;
}
cout<<ans<<endl;
}
}
return 0;
}

HDU 1757 A Simple Math Problem(矩阵)的更多相关文章

  1. HDU 1757 A Simple Math Problem (矩阵快速幂)

    题目 A Simple Math Problem 解析 矩阵快速幂模板题 构造矩阵 \[\begin{bmatrix}a_0&a_1&a_2&a_3&a_4&a ...

  2. HDU 1757 A Simple Math Problem 【矩阵经典7 构造矩阵递推式】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=1757 A Simple Math Problem Time Limit: 3000/1000 MS (J ...

  3. hdu 1757 A Simple Math Problem (乘法矩阵)

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  4. HDU 1757 A Simple Math Problem (矩阵乘法)

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  5. HDU 1757 A Simple Math Problem(矩阵高速幂)

    题目地址:HDU 1757 最终会构造矩阵了.事实上也不难,仅仅怪自己笨..= =! f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + -- + a9 ...

  6. HDU 1757 A Simple Math Problem(矩阵快速幂)

    题目链接 题意 :给你m和k, 让你求f(k)%m.如果k<10,f(k) = k,否则 f(k) = a0 * f(k-1) + a1 * f(k-2) + a2 * f(k-3) + …… ...

  7. hdu 1757 A Simple Math Problem(矩阵快速幂乘法)

    Problem Description Lele now is thinking about a simple function f(x). If x < f(x) = x. If x > ...

  8. hdu 1757 A Simple Math Problem (矩阵快速幂)

    Description Lele now is thinking about a simple function f(x). If x < 10 f(x) = x. If x >= 10 ...

  9. hdu 1757 A Simple Math Problem (矩阵快速幂,简单)

    题目 也是和LightOJ 1096 和LightOJ 1065 差不多的简单题目. #include<stdio.h> #include<string.h> #include ...

随机推荐

  1. bilibili的直播第三方IJKMediaFramework.framework下载打包使用教程

    参考和引用的地址: http://www.code4app.com/thread-8941-1-1.html http://blog.csdn.net/cccallen/article/details ...

  2. 创建本地SVN版本库以及将SVN导入GIT

    创建本地SVN 通常SVN作为一种服务,是在服务器上架设,供用户通过网络访问使用.但如果只是自己日常使用,完全可以架设在本机上,不需要启动后台程序,通过文件的方式访问即可. 建立本地SVN非常简单,一 ...

  3. 查询大数据表的效率对比:Linq to SQL、Entity Framework、企业库存储过程、ADO.Net

    最近因为要开发大数据量网站,特作比较. Linq to SQL 查询 记录数:399997Linq to SQL 查询 Milliseconds:1910视图查询 记录数:399997视图查询 Mil ...

  4. Uniform Resource Name Server

    HTTP The Definitive Guide 按址标识 identify by address 按名标识 identify by name Domain Name Server Uniform ...

  5. xcrun: error: unable to find utility "PackageApplication", not a developer tool or in PATH

    Xcode升级到8.3后 用命令进行打包 提示下面这个错误 xcrun: error: unable to find utility "PackageApplication", n ...

  6. Python开发【笔记】:列表转字典

    列表转字典 it = [1,2,3,4] print(dict(zip(it, it))) # {1: 1, 2: 2, 3: 3, 4: 4} it = iter(it) print(dict(zi ...

  7. linux strncpy()和strcat使用总结

    strcat原型:char *strcat(char *dest,const char *src); 把src所指字符串添加到dest结尾处(覆盖dest结尾处的'\0')并添加'\0'.src和de ...

  8. rem设置

    html{ font-size:10vw; }

  9. Maven项目Update Project后JRE System Library自动变回1.5解决办法

    最近在搭建Spring Boot项目<一步步搭建 Spring Boot maven 框架的工程>的时候,虽然设置JRE System Library为1.8,但是,当我 用 Maven ...

  10. ext3文件系统挂载优化--HBase

    1.设置noatime属性禁止记录文件访问时间戳以减少内核的管理开销 2.优化磁盘每个块为关键系统进程保留的固定空间:这个功能对关键磁盘比较有用, 比如操作系统依赖的磁盘,但这个功能对于数据存储来说几 ...