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) + …… + a9 * f(k-10);
思路 :先具体介绍一下矩阵快速幂吧,刚好刚刚整理了网上的资料。可以先了解一下这个是干嘛的,怎么用。
这个怎么弄出来的我就不说了,直接看链接吧,这实在不是我强项,点这儿,这儿也行
//HDU 1757
#include <iostream>
#include <stdio.h> using namespace std; struct matrix
{
int m[][] ;
} b,tp,res,init ; int n,m ; matrix Mul(matrix a,matrix b)
{
matrix c ;
for(int i = ; i < ; i++)
{
for(int j = ; j < ; j++)
{
c.m[i][j] = ;
for(int k = ; k < ; k++)
{
c.m[i][j] += (a.m[i][k] * b.m[k][j]) % m ;
c.m[i][j] %= m ;
}
}
}
return c ;
} matrix matrix_mi(matrix p,int k)
{
matrix t = res;
for(int i = ; i <= ; i++) t.m[i][i] = ;
while(k)
{
if(k & )
t = Mul(t,p) ;
k >>= ;
p = Mul(p,p) ;
}
return t ;
} void Init()
{
for(int i = ; i < ; i++)
for(int j = ; j < ; j++)
if(i- == j)
init.m[i][j]=;
else
init.m[i][j]=;
}
int main()
{
Init() ;
while(~scanf("%d %d",&n,&m))
{
b = init ;
for(int i = ; i < ; i++)
scanf("%d",&b.m[][i]) ;
for(int i = ; i < ; i++)
for(int j = ; j < ; j++)
if(i==j)
res.m[i][j] = ;
else
res.m[i][j] = ;
if(n >= )
{
int sum = ;
tp = matrix_mi(b,n-) ;
for(int i = ; i < ; i++)
sum += (tp.m[][i] * (-i))%m ;
printf("%d\n",sum%m) ;
}
else printf("%d\n",n%m) ;
}
return ;
}
HDU 1757 A Simple Math Problem(矩阵快速幂)的更多相关文章
- HDU 1757 A Simple Math Problem (矩阵快速幂)
题目 A Simple Math Problem 解析 矩阵快速幂模板题 构造矩阵 \[\begin{bmatrix}a_0&a_1&a_2&a_3&a_4&a ...
- hdu 1757 A Simple Math Problem_矩阵快速幂
题意:略 简单的矩阵快速幂就行了 #include <iostream> #include <cstdio> #include <cstring> using na ...
- HDU 1757 A Simple Math Problem(矩阵)
A Simple Math Problem [题目链接]A Simple Math Problem [题目类型]矩阵快速幂 &题解: 这是一个模板题,也算是入门了吧. 推荐一个博客:点这里 跟 ...
- HDU1757 A Simple Math Problem 矩阵快速幂
A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- A Simple Math Problem(矩阵快速幂)----------------------蓝桥备战系列
Lele now is thinking about a simple function f(x). If x < 10 f(x) = x. If x >= 10 f(x) = a0 ...
- 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 ...
- 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 ...
- hdu 1757 A Simple Math Problem (矩阵快速幂,简单)
题目 也是和LightOJ 1096 和LightOJ 1065 差不多的简单题目. #include<stdio.h> #include<string.h> #include ...
- HDU 1757 A Simple Math Problem( 矩阵快速幂 )
<font color = red , size = '4'>下列图表转载自 efreet 链接:传送门 题意:给出递推关系,求 f(k) % m 的值, 思路: 因为 k<2 * ...
随机推荐
- Oracle 一些操作
Achivelog ============================ alter system set db_recovery_file_dest='F:\ORACLE\recovery_ar ...
- C#判断Textbox是否为数字
第一种方法: try { ) { //操作代码 } else { MessageBox.Show("必须是正整数"); } } catch (FormatException) { ...
- (转)实战Memcached缓存系统(1)Memcached基础及示例程序
1.Cache定义 (1)狭义概念:用于CPU的相对高速处理与主存(Main Memory)的相对低速处理的之间起到协调功能的硬件设备. (2)广义概念:用于速度相差较大的两种硬件之间,起到协调两者数 ...
- JS实现登录页面记住密码和enter键登录
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>按 ...
- Jquery 自定义事件实现发布/订阅
//用户点击logoff按钮时,广播一个自定义事件,给任何需要保存状态的感兴趣的观察者,然后导航到logoff页面 $('#logoff').click(function(){ $.event.tri ...
- a2x
#include <typeinfo> template <typename T> bool a2x( T& _f , char* p) { if( !p ) retu ...
- 《RHEL6.3 FTP服务器虚拟用户的配置(含图)》——如此简单
虚拟用户就是传说中的ftp服务vip用户,大致分为这么几步: 1.安装ftp软件包 yum install *ftp* 2.启动vsftpd服务 /etc/init.d/vsftpd restart ...
- dom4j api 详解--XPath 节点详解
dom4j api 详解 http://871421448.iteye.com/blog/1546955 XPath 节点 http://www.w3school.com.cn/xpath/xpath ...
- WF 快速入门
WF(Windows Workflow Foundation ,中文译为:Windows工作流基础)是一种基于更高级抽象概念的编程语言,适合于实现业务流程.虽然可以通过使用图形化的工具(Workflo ...
- C# 学习之旅(2)--- 意外的收获
今天在完成老师布置的C#作业(计算一元二次方程的根)的时候,收获到意外的知识,所以写此博文予以记录. 意外收获为: 对文本框的输入值进行检测,使之按照要求格式输入. 下面是整个的源代码: using ...