题意:当x < 10时, f(x) = x;

当x >= 10 时,f(x) = a0 * f(x-1) + a1 * f(x-2) +  + a2 * f(x-3) + …… + a9 * f(x-10);
ai(0<=i<=9) 只能是0或者1 ,给出a0 ~ a9,k和m,计算f(k)%m(k<2*10^9 , m < 10^5)。

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1757

——>>构造矩阵,快速幂求解。

用excel弄了个~~

#include <cstdio>
#include <cstring> using namespace std; const int maxn = 10 + 5;
int k, mod, n; struct Mar{ //矩阵
int m[maxn][maxn];
Mar(){
memset(m, 0, sizeof(m));
}
}; Mar operator + (Mar a, Mar b){ //矩阵+
Mar ret;
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++) ret.m[i][j] = (a.m[i][j] + b.m[i][j]) % mod;
return ret;
} Mar operator * (Mar a, Mar b){ //矩阵*
Mar ret;
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
for(int l = 0; l < n; l++) ret.m[i][j] = (ret.m[i][j] + a.m[i][l] * b.m[l][j]) % mod;
return ret;
} Mar pow_mod(Mar a, int n){ //矩阵快速幂
if(n == 1) return a;
Mar x = pow_mod(a, n/2);
x = x * x;
if(n&1) x = x * a;
return x;
} void solve(){
Mar A;
n = 10;
int i, j, ret = 0;
for(i = 0; i < n; i++) scanf("%d", &A.m[0][i]);
if(k < 10) ret = k % mod;
else{
for(i = 1, j = 0; i < n; i++, j++) A.m[i][j] = 1;
A = pow_mod(A, k-9);
for(i = 0, j = 9; i < n; i++, j--) ret = (ret + A.m[0][i] * j) % mod;
}
printf("%d\n", ret);
} int main()
{
while(scanf("%d%d", &k, &mod) == 2) solve();
return 0;
}

hdu - 1757 - A Simple Math Problem的更多相关文章

  1. 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 ...

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

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

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

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

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

    A Simple Math Problem [题目链接]A Simple Math Problem [题目类型]矩阵快速幂 &题解: 这是一个模板题,也算是入门了吧. 推荐一个博客:点这里 跟 ...

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

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

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

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

  7. 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) + …… ...

  8. 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 > ...

  9. 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 ...

随机推荐

  1. Oracle EBS-SQL (PO-1):检查供货比例异常.sql

    select distinct msr.sourcing_rule_name                     名称 , msi.description                      ...

  2. service:jmx:rmi:///jndi/rmi

    service:jmx:rmi:///jndi/rmi://ip:9889/jmxrmi http://stackoverflow.com/questions/2768087/explain-jmx- ...

  3. java转换字符串的编码(转)

    package com.Alex.base; import java.io.UnsupportedEncodingException; /** * 转换字符串的编码 */ public class C ...

  4. C语言的本质(10)——指针本质

    指针,大概是C语言中最难理解的概念之一了.指针这个东西是C语言中的一个基本概念,C99中对于指针的定义是: 1. 指针的类型是derived from其它类型,也就是说指针的类型是由它指向的类型决定的 ...

  5. 1.2 linear SVM 推导

    1.将公式中的distance具体化 将$w_0$单独抽出作为$b$,$w=(w_1,...,w_n),x=(x_1,...,x_n)$ 则分割平面为:$w^Tx+b=0$ A.证明w为法向量     ...

  6. C# linq to xml

    XDocument doc = new XDocument( new XDeclaration("1.0", "utf-8", "yes") ...

  7. O2O领域添新军,正品网加快布局的战略考量

    前不久.正品网採购虚拟运营商30万170号码的招标公告引发了业界的广泛关注.一方面,虚拟运营商正处于"徘徊不定"的十字路口.据业内知情人士透露,眼下12家虚拟运营商企业共放号在20 ...

  8. Mvc里查询商品页面

    /// <summary> /// 商品小类筛选页面 GoodsTypeName ----------------SelectGoods--商品筛选 --图文 /// Home/Selec ...

  9. 在 IIS 中配置 ASP.NET 应用程序

     注意事项: 1.注册.NET 如果先安装.net平台,后安装IIS,那么在IIS中可能就没有出现ASP.NET版本的下拉菜单,就要手动注册: 一般.Net版本都存放在:C:\WINDOWS\Micr ...

  10. org.hibernate.QueryException: could not resolve property: address of:

    Hibernate: select count(*) as y0_ from test.course this_ org.hibernate.QueryException: could not res ...