233 Matrix
有一\(n\times m\)的矩阵\(\{a\}\),定义\(a[0][0]=0,a[0][1]=233,a[0][2]=2333,a[0][3]=23333...\),然后给出\(a[1][0],a[2][0],...,a[n][0]\),未给出或定义的位置满足\(a[i][j]=a[i-1][j]+a[i][j-1]\),询问\(a[n][m]\)的值\(mod\ 10000007\),\(n ≤ 10,m ≤ 10^9\)。
解
显然对于第0行,我们有转移方程\(a[0][i]=a[0][i-1]\times 10+3\),这个是可以转移的,显然需要增添辅助1,注意到n很小,故考虑整个压维,故设状态矩阵(以n=2为例)
\]
不难得知转移方程
\]
于是根据规律,填写转移矩阵和状态矩阵即可。
参考代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#define il inline
#define ri register
#define ll long long
#define yyb 10000007
using namespace std;
struct matrix{
ll jz[12][12];
il void clear(){
memset(jz,0,sizeof(jz));
}
il void unit(){
clear();ri int i;
for(i=0;i<12;++i)jz[i][i]=1;
}
il void print(){
ri int i,j;
for(i=0;i<12;++i,putchar('\n'))
for(j=0;j<12;++j)
printf("%lld ",jz[i][j]);
putchar('\n');
}
il matrix operator*(matrix x){
matrix y;y.clear();
ri int i,j,k;
for(i=0;i<12;++i)
for(j=0;j<12;y.jz[i][j]%=yyb,++j)
for(k=0;k<12;++k)
y.jz[i][j]+=jz[i][k]*x.jz[k][j]%yyb;
return y;
}template<class free>
il matrix operator^(free y){
matrix ans,x(*this);ans.unit();
while(y){
if(y&1)ans=ans*x;
x=x*x,y>>=1;
}return ans;
}
}tran,state;
int main(){
ll n,m;int i,j;
while(scanf("%lld%lld",&n,&m)!=EOF){
state.jz[0][0]=1,state.jz[0][1]=233;
for(i=2;i<=n+1;++i)scanf("%lld",&state.jz[0][i]);
tran.jz[0][0]=1,tran.jz[0][1]=3,tran.jz[1][1]=10;
for(i=2;i<=n+1;++i)
for(j=1;j<=i;++j)
tran.jz[j][i]=1;
state=state*(tran^m);
printf("%lld\n",state.jz[0][n+1]);
tran.clear(),state.clear();
}
return 0;
}
233 Matrix的更多相关文章
- [HDU5015]233 Matrix
[HDU5015]233 Matrix 试题描述 In our daily life we often use 233 to express our feelings. Actually, we ma ...
- HDU5015 233 Matrix(矩阵高速幂)
HDU5015 233 Matrix(矩阵高速幂) 题目链接 题目大意: 给出n∗m矩阵,给出第一行a01, a02, a03 ...a0m (各自是233, 2333, 23333...), 再给定 ...
- 233 Matrix(hdu5015 矩阵)
233 Matrix Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- Spring-1-I 233 Matrix(HDU 5015)解题报告及测试数据
233 Matrix Time Limit:5000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Descript ...
- 233 Matrix(矩阵快速幂+思维)
In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23333, or 233 ...
- ACM学习历程——HDU5015 233 Matrix(矩阵快速幂)(2014陕西网赛)
Description In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 2 ...
- HDU - 5015 233 Matrix(杨辉三角/前缀+矩阵快速幂)
233 Matrix In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23 ...
- HDU5015 233 Matrix —— 矩阵快速幂
题目链接:https://vjudge.net/problem/HDU-5015 233 Matrix Time Limit: 10000/5000 MS (Java/Others) Memor ...
- HDU 5015 233 Matrix(网络赛1009) 矩阵快速幂
先贴四份矩阵快速幂的模板:http://www.cnblogs.com/shangyu/p/3620803.html http://www.cppblog.com/acronix/archive/20 ...
- hdu 5015 233 Matrix (矩阵高速幂)
233 Matrix Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tota ...
随机推荐
- c语言NULL和0区别及NULL详解
先看下面一段代码输出什么: #include<stdo.h> int main() { int *p=NULL; printf("%s",p); } 输出<n ...
- Java--会移动、反弹的球
package firstpack; import java.awt.*; public class MyStar { public static void main(String[] args) { ...
- LeetCode 175. Combine Two Tables (组合两个表)
题目标签: 题目给了我们两个table,让我们合并,根据Person为主. 因为题目说了 提供person 信息,不管这个人有没有地址.所以这里用Left Join. Java Solution: R ...
- jquery实现点击按钮弹出层和点击空白处隐藏层
昨天做项目遇到一个问题,和大家分享下,jquery实现点击按钮弹出层和点击空白处隐藏层的问题 if($('.autoBtn').length){ $('.autoBtn' ...
- WebApi 路由机制剖析
阅读目录 一.MVC和WebApi路由机制比较 1.MVC里面的路由 2.WebApi里面的路由 二.WebApi路由基础 1.默认路由 2.自定义路由 3.路由原理 三.WebApi路由过程 1.根 ...
- 2019-6-23-win10-uwp-开发-CSDN-访问量统计-源代码
title author date CreateTime categories win10 uwp 开发 CSDN 访问量统计 源代码 lindexi 2019-6-23 11:2:1 +0800 2 ...
- 三角形的实现和盒模型、层模型、浮动模型、定位、权重、margin问题
相邻的border会平分所占的区域,出现一个斜线, .my_triangle{ width: 10px; height: 10px; background-color: blue; border-wi ...
- try install gitlab ce at docker ce
sudo docker run --detach \ --env GITLAB_OMNIBUS_CONFIG="external_url 'http://192.168.1.30:8087/ ...
- mysql出现You can’t specify target table for update in FROM clause
在mysql执行下面语句时报错: You can’t specify target table for update in FROM clause UPDATE edu_grade_hgm_1 ' W ...
- leetcode-227-基本计算器②
题目描述: 方法一:中缀转后缀 #!_*_coding:utf-8_*_ class Solution: def calculate(self, s: str) -> int: def in_t ...