HDU - 5015 233 Matrix (矩阵快速幂)
InputThere are multiple test cases. Please process till EOF.
For each case, the first line contains two postive integers n,m(n ≤ 10,m ≤ 10 9). The second line contains n integers, a 1,0,a 2,0,...,a n,0(0 ≤ a i,0 < 2 31).OutputFor each case, output a n,m mod 10000007.Sample Input
- 1 1
- 1
- 2 2
- 0 0
- 3 7
- 23 47 16
Sample Output
- 234
- 2799
- 72937
- 题意:
a[i][j]=a[i-1][j]+a[i][j-1];
a[0][1]=233,a[0][2]=2333,a[0][3]=23333,......
a[1][0]到a[n][0]由输入给出,求a[n][m];
- 思路:
本来打算直接用a[i][j]=a[i-1][j]+a[i][j-1]作为公式进行推导,发现并不可行。
实际上是直接对每一列进行操作。
写完这题,大概矩阵快速幂才是真的入门。
- #include<iostream>
- #include<algorithm>
- #include<vector>
- #include<stack>
- #include<queue>
- #include<map>
- #include<set>
- #include<cstdio>
- #include<cstring>
- #include<cmath>
- #include<ctime>
- #define fuck(x) cout<<#x<<" = "<<x<<endl;
- #define debug(a,i) cout<<#a<<"["<<i<<"] = "<<a[i]<<endl;
- #define ls (t<<1)
- #define rs ((t<<1)+1)
- using namespace std;
- typedef long long ll;
- typedef unsigned long long ull;
- const int maxn = ;
- const int maxm = ;
- const int inf = 2.1e9;
- const ll Inf = ;
- const int mod = ;
- const double eps = 1e-;
- const double pi = acos(-);
- ll num[];
- struct Matrix{
- ll mp[][];
- };
- Matrix mul(Matrix a,Matrix b,int n){
- Matrix ans;
- for(int i=;i<=n;i++){
- for(int j=;j<=n;j++){
- ans.mp[i][j]=;
- for(int k=;k<=n;k++){
- ans.mp[i][j]+=a.mp[i][k]*b.mp[k][j];
- }
- ans.mp[i][j]%=mod;
- }
- }
- return ans;
- }
- Matrix q_pow(Matrix a,int b,int n){
- Matrix ans;
- memset(ans.mp,,sizeof(ans.mp));
- for(int i=;i<=n;i++){
- ans.mp[i][i]=;
- }
- while (b){
- if(b&){
- ans=mul(ans,a,n);
- }
- b>>=;
- a=mul(a,a,n);
- }
- return ans;
- }
- int main()
- {
- // ios::sync_with_stdio(false);
- // freopen("in.txt","r",stdin);
- int n,m;
- while(scanf("%d%d",&n,&m)!=EOF){
- for(int i=;i<=n;i++){
- scanf("%lld",&num[i]);
- }
- Matrix exa;
- memset(exa.mp,,sizeof(exa.mp));
- int t=;
- exa.mp[n+][n+]=;
- for(int i=;i<=n+;i++){
- exa.mp[i][]=;exa.mp[i][n+]=;
- for(int j=;j<=t;j++){
- exa.mp[i][j+]=;
- }
- t++;
- }
- exa=q_pow(exa,m,n+);
- ll ans=;
- num[]=;num[n+]=;
- for(int i=;i<=n+;i++){
- ans+=exa.mp[n+][i]*num[i-];
- ans%=mod;
- }
- printf("%lld\n",ans);
- }
- return ;
- }
HDU - 5015 233 Matrix (矩阵快速幂)的更多相关文章
- HDU 5015 233 Matrix --矩阵快速幂
题意:给出矩阵的第0行(233,2333,23333,...)和第0列a1,a2,...an(n<=10,m<=10^9),给出式子: A[i][j] = A[i-1][j] + A[i] ...
- 233 Matrix 矩阵快速幂
In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23333, or 233 ...
- 233 Matrix(矩阵快速幂+思维)
In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23333, or 233 ...
- HDU5015 233 Matrix —— 矩阵快速幂
题目链接:https://vjudge.net/problem/HDU-5015 233 Matrix Time Limit: 10000/5000 MS (Java/Others) Memor ...
- HDU.1575 Tr A ( 矩阵快速幂)
HDU.1575 Tr A ( 矩阵快速幂) 点我挑战题目 题意分析 直接求矩阵A^K的结果,然后计算正对角线,即左上到右下对角线的和,结果模9973后输出即可. 由于此题矩阵直接给出的,题目比较裸. ...
- HDU5015 233 Matrix(矩阵高速幂)
HDU5015 233 Matrix(矩阵高速幂) 题目链接 题目大意: 给出n∗m矩阵,给出第一行a01, a02, a03 ...a0m (各自是233, 2333, 23333...), 再给定 ...
- hdu 3117 Fibonacci Numbers 矩阵快速幂+公式
斐波那契数列后四位可以用快速幂取模(模10000)算出.前四位要用公式推 HDU 3117 Fibonacci Numbers(矩阵快速幂+公式) f(n)=(((1+√5)/2)^n+((1-√5) ...
- HDU 5015 233 Matrix(网络赛1009) 矩阵快速幂
先贴四份矩阵快速幂的模板:http://www.cnblogs.com/shangyu/p/3620803.html http://www.cppblog.com/acronix/archive/20 ...
- HDU 2842 (递推+矩阵快速幂)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2842 题目大意:棒子上套环.第i个环能拿下的条件是:第i-1个环在棒子上,前i-2个环不在棒子上.每个 ...
随机推荐
- 跟我一起认识axure(二)
创建企业网站页面步骤 第一步修改这里 变成 第一部分就完成了 第二部分部件窗口 在Axure中设计页面像小时候玩的拼图游戏,那么部件窗口就是专门用来存放拼图块的容器 使用部件窗口中常用的部件设计欢迎页 ...
- #define 和常量 const 的区别
const 后的常量,程序对其中只能读不能修改. #include <iostream> using namespace std; int main() { const double pi ...
- chrome://inspect调试html页面空白,DOM无法加载的解决方案
chrome://inspect调试html页面空白,DOM无法加载的解决方案 先描述一下问题 有一段时间没碰huilder hybird app 开发了,今天调试的时候 chrome://inspe ...
- SSH applicationContext.xml import异常
近期在项目上,遇到了一个问题.在配置applicationContext.xml使用<import>标签引入其他的xml文件时,导致项目启动时过慢.有时还会引起启动异常.后来查到是xml文 ...
- KiCad EDA 过孔是否可以开窗?
KiCad EDA 过孔是否可以开窗? 和传统的商业 EDA 不同,KiCad EDA 的过孔默认就是盖绿油. 在 KiCad 的过孔界面没有任何可以设置的地方,这也有一个好处,不过考虑过孔是否盖油. ...
- qt中绘制文字
(1)颜色QPen (2) 字体QFont (3)位置与对齐 void CircleWidget::paintEvent(QPaintEvent *event) { QPainter painter( ...
- Python基础:13装饰器
装饰器是一个很著名的设计模式,经常被用于有切面需求的场景,较为经典的应用有插入日志.性能测试.事务处理等.装饰器是解决这类问题的绝佳设计,有了装饰器,我们就可以抽离出大量函数中与函数功能本身无关的雷同 ...
- Part17—触摸屏显身手—Part17.1—原理简介
- HSV 和 HLS颜色空间
颜色空间 颜色空间是特定的颜色组织:它提供了将颜色分类,并以数字图像表示的方法. RGB 是红绿蓝颜色空间.你可以将其视为 3D 空间,在这种情况下是立方体,其中任何颜色都可以用 R.G 和 B 值的 ...
- ras 加解密类,支持截取
class RsaEncrypt{ private $_privateKey = false; private $_publicKey = false; /** * 私钥解密 * @param $da ...