hdu1757
来源:互联网 发布:js设置innerhtml 编辑:程序博客网 时间:2024/05/22 18:40
链接:点击打开链接
题意: 当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),求f(k)%m
代码:
#include <iostream>#include <stdio.h>#include <string.h>using namespace std;struct node{ long long m[10][10];};long long m;node P={0,0,0,0,0,0,0,0,0,0, 1,0,0,0,0,0,0,0,0,0, 0,1,0,0,0,0,0,0,0,0, 0,0,1,0,0,0,0,0,0,0, 0,0,0,1,0,0,0,0,0,0, 0,0,0,0,1,0,0,0,0,0, 0,0,0,0,0,1,0,0,0,0, 0,0,0,0,0,0,1,0,0,0, 0,0,0,0,0,0,0,1,0,0, 0,0,0,0,0,0,0,0,1,0}; //根据表达式构造出矩阵node I={1,0,0,0,0,0,0,0,0,0, 0,1,0,0,0,0,0,0,0,0, 0,0,1,0,0,0,0,0,0,0, 0,0,0,1,0,0,0,0,0,0, 0,0,0,0,1,0,0,0,0,0, 0,0,0,0,0,1,0,0,0,0, 0,0,0,0,0,0,1,0,0,0, 0,0,0,0,0,0,0,1,0,0, 0,0,0,0,0,0,0,0,1,0, 0,0,0,0,0,0,0,0,0,1,};node mul(node a,node b){ int i,j,k; node c; for(i=0;i<10;i++) for(j=0;j<10;j++){ c.m[i][j]=0; for(k=0;k<10;k++) c.m[i][j]+=(a.m[i][k]*b.m[k][j])%m; c.m[i][j]%=m; } return c;}node quickmod(long long n){ node a,b; a=P;b=I; while(n){ if(n&1) b=mul(b,a); n/=2; a=mul(a,a); } return b;} //矩阵快速幂模板long long a[20];int main(){ long long k,i,sum; node temp; while(cin>>k>>m){ for(i=0;i<10;i++) cin>>a[i]; if(k<10){ cout<<k%m<<endl; continue; } //小于10的时候单独判断 for(i=0;i<10;i++) P.m[0][i]=a[i]; temp=quickmod(k-9); sum=0; for(i=0;i<10;i++) sum+=(temp.m[0][i]*(9-i))%m; sum%=m; cout<<sum<<endl; } return 0;}
0 0
- hdu1757
- hdu1757
- HDU1757
- hdu1757 快速幂
- HDU1757-矩阵相乘
- HDU1757 矩阵快速幂
- HDU1757(矩阵快速幂)
- hdu1757 矩阵快速幂--
- 快速矩阵幂 HDU1757
- hdu1757(矩阵加速)
- 矩阵快速幂 HDU1757
- -----hdu1757 矩阵连乘
- 矩阵快速幂 hdu1757
- A Simple Math Problem hdu1757
- hdu1757 A Simple Math Problem
- HDU1757矩阵的简单运用
- HDU1757 A Simple Math Problem
- HDU1757 A Simple Math Problem
- 冒泡排序算法
- 拓展欧几里得学习小记
- nc后台两张单同名字字段数据交换
- [POJ2104] K-th Number/[POJ2761] Feed the dogs
- iOS 以byte数组作为密钥的3des加密
- hdu1757
- HDU 2255 奔小康赚大钱 POJ 2195 Going Home 最大权完美匹配 KM算法
- 在Eclipse中安装Maven插件以及创建Maven项目
- Java学习个人笔记---Java数组内存
- button放在form表单导致点击按钮触发的ajax报错问题
- IOS 自动约束
- POJ 1564 Sum It Up
- noip1999 回文数 (模拟)
- HDU1179Ollivanders: Makers of Fine Wands since 382 BC.(最大匹配)