hdu------(1757)A Simple Math Problem(简单矩阵快速幂)
A Simple Math Problem
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2791 Accepted Submission(s): 1659
If x < 10 f(x) = x.
If x >= 10 f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + …… + a9 * f(x-10);
And ai(0<=i<=9) can only be 0 or 1 .
Now, I will give a0 ~ a9 and two positive integers k and m ,and could you help Lele to caculate f(k)%m.
In each case, there will be two lines.
In the first line , there are two positive integers k and m. ( k<2*10^9 , m < 10^5 )
In the second line , there are ten integers represent a0 ~ a9.
1 1 1 1 1 1 1 1 1 1
20 500
1 0 1 0 1 0 1 0 1 0
104
//#define LOCAL
#include<cstdio>
#include<cstring>
#define LL __int64
using namespace std;
const int maxn=;
LL k,m;
int aa[maxn],mat[maxn][maxn];
int ans[maxn][maxn]; void init()
{
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
if(i==)
mat[i][j]=aa[j];
else
if(i==j+)mat[i][j]=;
else mat[i][j]=;
if(i==j)
ans[i][j]=;
else ans[i][j]=;
}
}
} void Matrix(int a[][],int b[][])
{ int c[][];
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
c[i][j]=;
for(int k=;k<;k++)
{
c[i][j]=(c[i][j]+a[i][k]*b[k][j])%m;
}
}
}
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
a[i][j]=c[i][j];
}
}
} void pow(LL n)
{
while(n>)
{
if(n&) Matrix(ans,mat);
n>>=1L;
if(n==)break;
Matrix(mat,mat);
}
} int main()
{
#ifdef LOCAL
freopen("test.in","r",stdin);
#endif while(scanf("%I64d%I64d",&k,&m)!=EOF)
{
for(int i=;i<;i++)
scanf("%d",aa+i);
if(k<) printf("%I64d\n",k%m);
else
{
init();
pow(k-);
int res=;
for(int i=;i<;i++)
res=(res+(-i-)*ans[][i])%m;
printf("%d\n",res);
}
}
return ;
}
hdu------(1757)A Simple Math Problem(简单矩阵快速幂)的更多相关文章
- hdu 1757 A Simple Math Problem (矩阵快速幂,简单)
题目 也是和LightOJ 1096 和LightOJ 1065 差不多的简单题目. #include<stdio.h> #include<string.h> #include ...
- 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) + …… ...
- 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( 矩阵快速幂 )
<font color = red , size = '4'>下列图表转载自 efreet 链接:传送门 题意:给出递推关系,求 f(k) % m 的值, 思路: 因为 k<2 * ...
- 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 > ...
- HDU 1757 A Simple Math Problem(矩阵快速幂模板)
题意:题意很简单,不多说了. 思路: |f(10) | |a0 a1 a2 ...a8 a9| |f(9)|| f(9) | | 1 0 0 ... 0 ...
- HDU 1757 A Simple Math Problem(矩阵高速幂)
题目地址:HDU 1757 最终会构造矩阵了.事实上也不难,仅仅怪自己笨..= =! f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + -- + a9 ...
- hdu 1757 A Simple Math Problem (矩阵高速幂)
和这一题构造的矩阵的方法同样. 须要注意的是.题目中a0~a9 与矩阵相乘的顺序. #include <iostream> #include <cstdio> #include ...
- HDU1757-A Simple Math Problem,矩阵快速幂,构造矩阵水过
A Simple Math Problem 一个矩阵快速幂水题,关键在于如何构造矩阵.做过一些很裸的矩阵快速幂,比如斐波那契的变形,这个题就类似那种构造.比赛的时候手残把矩阵相乘的一个j写成了i,调试 ...
随机推荐
- CUBRID学习笔记 39 net使用dataset 返回查询的数据
using CUBRID.Data.CUBRIDClient; namespace DataSetExample { class Program { static ...
- CSS笔记(十)position属性与定位
参考:http://www.w3school.com.cn/cssref/pr_class_position.asp position属性规定了元素的定位类型.任何元素都可定位,其中,绝对或固定元素会 ...
- css3 3d学习笔记
几个属性: -webkit-perspective:0;景深(默认0), -webkit-perspective-origin:center center;景深基点(默认中间), -webkit-tr ...
- Memcached通用类(基于Memcached Client Library)
分享下自己编写的Memcached通用类.欢迎大家帮忙指点下哈~ 使用的是.NET memcached client library 客户端+Memcached Providers using Sys ...
- c++ vector 简单实现。
第二次修改: 1)熟悉基本的模板编程,头文件和定义必须放到一起. 2)熟悉内存管理模板类 allocator<T>. 1.使用标准库的内存管理类 allocator<T> 代替 ...
- 优秀c++开源项目集合
本文会持续更新, 我希望通过这篇文章把我看到过的优秀开源项目记录下来, 有时间仔细阅读. cockroachdb 前googler开发的开源的spanner数据库: https://github.co ...
- python仿微软记事本
# -*- coding=utf-8 -*- from tkinter import filedialog import tkinter as tk import tkinter.scrolledte ...
- jquery_dialog实现效果
jquery_dialog实现效果 jquery_dialog.js <!-- /******************************************************** ...
- 教你如何精通Struts:Tiles框架
Tiles框架特性和内容 Tiles框架为创建Web页面提供了一种模板机制,它能将网页的布局和内容分离.它允许先创建模板,然后在运行时动态地将内容插入到模板中.Tiles 框架建立在JSP的inclu ...
- iOS开发之 xcode6 APP 打包提交审核详细步骤
一. 在xcode6.1和ios10.10.1环境下实现app发布 http://blog.csdn.net/mad1989/article/details/8167529 http://jingya ...