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 * ...
随机推荐
- android不依赖具体activity弹出Dialog对话框,即全局性对话框
最近在DialogUtil类中声明了一个静态的弹出Dialog方法,弹出的Dialog也是静态的,并且只在第一次进行创建,由于Dialog弹出依附于Activity,所以就出现了问题. 即:第一次调用 ...
- 个人实验记录之EIGRP基本配置
一.EIGRP的基本配置 1(1).进入接口配置IP R1(config)#inter s1/0 R1(config-if)#ip address 200.1.1.1 255.255.255.0 R1 ...
- Excel Operation
在日常工作中, 常常需要收集统计一些数据, 然后整理到excel, 这种重复性的操作可以自己写个工具来实现. 采用HtmlUnitDriver 访问页面, 抓取数据, 再把数据列表通过调用POI放到e ...
- Cocos2d-x中停止播放背景音乐
停止背景音乐播放代码放置到什么地方比较适合呢?例如:在HelloWorld场景中,主要代码如下: bool HelloWorld::init() { return true; } void Hello ...
- react服务端/客户端,同构代码心得
FKP-REST是一套全栈javascript框架 react服务端/客户端,同构代码心得 作者:webkixi react服务端/客户端,同构代码心得 服务端,客户端同构一套代码,大前端的梦想, ...
- javascrip笔记——图片加载
var t_img; // 定时器 var isLoad = true; // 控制变量 // 判断图片加载状况,加载完成后回调 isImgLoad(function(){ // 加载完成 }); / ...
- Eclipse Class Decompiler---Java反编译插件
若转载,请标明出处http://www.cnblogs.com/last_hunter/p/5626779.html,谢谢! ------------------------------------- ...
- 【转】Linux网络编程入门
(一)Linux网络编程--网络知识介绍 Linux网络编程--网络知识介绍客户端和服务端 网络程序和普通的程序有一个最大的区别是网络程序是由两个部分组成的--客户端和服务器端. 客户 ...
- Xamarin android PreferenceActivity 实现应用程序首选项设置(一)
应用程序首选项屏幕 类似系统设置界面. PreferenceActivity 是另一种类型的Activity,通过PreferenceActivity 可以以最少量的工作显示某些Preference列 ...
- jQuery Mobile里xxx怎么用呀?(集成篇)
jQuery Mobile如何使用GA(Google Analytics)? 什么是GA: http://baike.baidu.com/view/34729.htm http://www.googl ...