HDU 1757
简单的矩阵构造题,参看我前几篇的谈到的矩阵的构造法。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; int Mod;
struct Matrax {
int m[15][15];
};
Matrax a,per;
int ats[15],an[15]; void initial(){
memset(per.m,0,sizeof(per.m));
memset(a.m,0,sizeof(a.m));
for(int i=0;i<10;i++){
a.m[i][0]=ats[i];
per.m[i][i]=1;
}
for(int i=1;i<10;i++){
a.m[i-1][i]=1;
}
for(int i=0;i<10;i++)
an[i]=10-i-1;
} Matrax multi(Matrax a,Matrax b){
Matrax c;
for(int i=0;i<10;i++){
for(int j=0;j<10;j++){
c.m[i][j]=0;
for(int k=0;k<10;k++)
c.m[i][j]=(c.m[i][j]+a.m[i][k]*b.m[k][j])%Mod;
}
}
return c;
} Matrax Power(int k){
Matrax ans=per,p=a;
while(k){
if(k&1){
ans=multi(ans,p);
}
k>>=1;
p=multi(p,p);
}
return ans;
} int main(){
int k;
while(scanf("%d%d",&k,&Mod)!=EOF){
for(int i=0;i<10;i++)
scanf("%d",&ats[i]);
if(k<10){
printf("%d\n",k);
continue;
}
initial();
Matrax ans=Power(k-9);
int sum=0;
for(int i=0;i<10;i++)
sum=(sum+an[i]*ans.m[i][0])%Mod;
printf("%d\n",sum);
}
return 0;
}
HDU 1757的更多相关文章
- 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(矩阵高速幂)
题目地址:HDU 1757 最终会构造矩阵了.事实上也不难,仅仅怪自己笨..= =! f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + -- + a9 ...
- hdu - 1757 - A Simple Math Problem
题意:当x < 10时, f(x) = x: 当x >= 10 时,f(x) = a0 * f(x-1) + a1 * f(x-2) + + a2 * f(x-3) + …… + a9 ...
- hdu 1757 (矩阵快速幂) 一个简单的问题 一个简单的开始
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1757 题意不难理解,当x小于10的时候,数列f(x)=x,当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 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- hdu 1757 矩阵
用矩阵表示状态,矩阵乘法的就是状态之间的变换 作一个vector: 要求的就是一个矩阵A,使得上面那个vector乘以A之后变成 解得A= [不知道用逆矩阵能不能直接求出A Ref:http://bl ...
- hdu 1757 A Simple Math Problem (乘法矩阵)
A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- 【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 >= 1 ...
- hdu 1757 矩阵快速幂 **
一看正确率这么高,以为是水题可以爽一发,结果是没怎么用过的矩阵快速幂,233 题解链接:点我 #include<iostream> #include<cstring> ; us ...
随机推荐
- 日积(Running)月累(ZSSURE):Task之Cancel、OpenAccess之Delete及fo-dicom之DeepCopy、
题记: 最近看了一篇关于架构方面的良心长文你的架构是怎样一步步腐化的?,文中字字句句道出了诸多从业者.初创企业,以及BAT都会遇到的问题,细细品读后认为工作生活中的诸多情况皆如此,都会有一个体量由小到 ...
- Quartz实例:quartz定时任务代码示例
转自:http://www.blogchong.com/post/96.html quartz定时任务调度框架,使用实例. Job类://即实际调度任务实现 . package net.csdn.ed ...
- HTML5动态时钟
实现效果 源码可以去github下载 地址:https://github.com/feifeiliu/jsBlock 参考:慕课网动态时钟
- Visual Studio写Cuda代码
1. 正常新建一个项目 2. 在项目中右键, build 选项中选择 CUDA 编译器 3. 项目属性中设置 CUDA 链接库 和 头文件 编译参数等 4. 完成 cu cuh 文 ...
- The name ‘InitialzeComponent’ does not exist in the current context
在Visual Studio中创建Windows Store项目,在MainPage.xaml.cs中出现错误: The name 'InitialzeComponent' does not exis ...
- javascript 公历与农历相互转换工具类
/** * 公历[1900-1-31,2100-12-31]时间区间内的公历.农历互转 * @charset UTF-8 * @Author Jea杨(JJonline@JJonline.Cn) * ...
- JDK和Cglib实现动态代理实例及优缺点分析
Spring AOP使用的核心技术是动态代理,说到动态代理就不得不和设计模式中的代理模式联系起来,通过代理模式我们可以对目标类进行功能增强,在某个方法的执行前后增加一些操作,例如计算方法执行效率.打印 ...
- WCF - NetCtP 双工错误列表
1. 在服务 Transfer 实现的协定列表中找不到协定名称 "IMetadataExchange" 将 ServiceMetadataBehavior 添加到配置文件或直接添加 ...
- 杭电2060WA
#include<stdio.h> int main() { int n,num,p,q,i,a[]={2,3,4,5,6,7}; scanf("%d",&n) ...
- js 按钮连击 减少触发事件次数
<body> <input type="button" onClick="testbtn()" value="测试按钮"& ...