CodeForcesGym 100735B Retrospective Sequence
Retrospective Sequence
This problem will be judged on CodeForcesGym. Original ID: 100735B
64-bit integer IO format: %I64d Java class name: (Any)
Retrospective sequence is a recursive sequence that is defined through itself. For example Fibonacci specifies the rate at which a population of rabbits reproduces and it can be generalized to a retrospective sequence. In this problem you will have to find the n-th Retrospective Sequence modulo MOD = 1000000009. The first (1 ≤ N ≤ 20) elements of the sequence are specified. The remaining elements of the sequence depend on some of the previous N elements. Formally, the sequence can be written as Fm = Fm - k1 + Fm - k2 + ... + Fm - ki + ... + Fm - kC - 1 + Fm - kC. Here, C is the number of previous elements the m-th element depends on, 1 ≤ ki ≤ N.
Input
The first line of each test case contains 3 numbers, the number (1 ≤ N ≤ 20) of elements of the retrospective sequence that are specified, the index (1 ≤ M ≤ 1018) of the sequence element that has to be found modulo MOD, the number (1 ≤ C ≤ N) of previous elements the i-th element of the sequence depends on.
The second line of each test case contains N integers specifying 0 ≤ Fi ≤ 10, (1 ≤ i ≤ N).
The third line of each test case contains C ≥ 1 integers specifying k1, k2, ..., kC - 1, kC (1 ≤ ki ≤ N).
Output
Output single integer R, where R is FM modulo MOD.
Sample Input
2 2 2
1 1
1 2
1
2 7 2
1 1
1 2
13
3 100000000000 3
0 1 2
1 2 3
48407255
Source
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL mod = ;
LL n,N,M,C;
struct Matrix{
LL m[][];
void init(){
memset(m,,sizeof m);
}
void setOne(){
init();
for(int i = ; i < ; ++i) m[i][i] = ;
}
Matrix(){
init();
}
Matrix operator*(const Matrix &rhs) const{
Matrix ret;
for(int k = ; k <= n; ++k)
for(int i = ; i <= n; ++i)
for(int j = ; j <= n; ++j)
ret.m[i][j] = (ret.m[i][j] + m[i][k]*rhs.m[k][j]%mod)%mod;
return ret;
}
void print(){
for(int i = ; i <= n; ++i){
for(int j = ; j <= n; ++j)
cout<<m[i][j]<<" ";
cout<<endl;
}
cout<<endl;
}
};
Matrix a,b;
void quickPow(LL index){
//Matrix ret;
//ret.setOne();
while(index){
if(index&) a = a*b;
index >>= ;
b = b*b;
}
//a = a*ret;
}
int main(){
while(~scanf("%I64d%I64d%I64d",&N,&M,&C)){
a.init();
b.init();
n = N;
for(int i = ; i <= N; ++i){
scanf("%I64d",&a.m[][i]);
b.m[i+][i]++;
}
for(int i = ,tmp; i <= C; ++i){
scanf("%d",&tmp);
b.m[N + - tmp][n]++;
}
if(M <= N){
printf("%I64d\n",a.m[][M]%mod);
continue;
}
quickPow(M - N);
printf("%I64d\n",a.m[][n]%mod);
}
return ;
}
/*
2 3 2
1 1
1 2 3 5 3
0 1 2
1 2 3
*/
CodeForcesGym 100735B Retrospective Sequence的更多相关文章
- CodeForcesGym 100641B A Cure for the Common Code
A Cure for the Common Code Time Limit: 3000ms Memory Limit: 262144KB This problem will be judged on ...
- oracle SEQUENCE 创建, 修改,删除
oracle创建序列化: CREATE SEQUENCE seq_itv_collection INCREMENT BY 1 -- 每次加几个 STA ...
- Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等
功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...
- DG gap sequence修复一例
环境:Oracle 11.2.0.4 DG 故障现象: 客户在备库告警日志中发现GAP sequence提示信息: Mon Nov 21 09:53:29 2016 Media Recovery Wa ...
- Permutation Sequence
The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- [LeetCode] Sequence Reconstruction 序列重建
Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...
- [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列
Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...
- [LeetCode] Verify Preorder Sequence in Binary Search Tree 验证二叉搜索树的先序序列
Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary ...
- [LeetCode] Longest Consecutive Sequence 求最长连续序列
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...
随机推荐
- 【转载】greenplum数据库引擎探究
Greenplum做为新一代的数据库引擎,有着良好的发展与应用前景.强大的工作效率,低成本的硬件平台对数据仓库与商业智能建设有很大的吸引力.要清楚的了解其特点最好从架构着手. 架构分析 Greenp ...
- E20171028-hm
stick n. 棍棒,棍枝; 枝条; 操纵杆; 球棍; stopwatch n. (赛跑等记时用的) 秒表,跑表; agency n. 代理; 机构; 力量; various adj. ...
- 微信小程序压缩图片并上传到服务器(拿去即用)
这里注意一下,图片压缩后的宽度是画布宽度的一半 canvasToTempFilePath 创建画布的时候会有一定的时间延迟容易失败,这里加setTimeout来缓冲一下 这是单张图片压缩,多张的压缩暂 ...
- hastable 用法
一,哈希表(Hashtable)简述 在.NET Framework中,Hashtable是System.Collections命名空间提供的一个容器,用于处理和表现类似keyvalue的键值对,其中 ...
- MyBatis 配置控制台上显示sql语句(log4j.properties 之三)
### direct log messages to stdout ###log4j.appender.stdout=org.apache.log4j.ConsoleAppenderlog4j.app ...
- Elasticsearch_Lucene基础
Lucene基本概念 文档(document):索引与搜索的主要载体,它包含一个或多个字段,存放将要写入索引的或将从索引搜索出来的数据. 字段(field):文档的一个片段,它包含字段的名称和字段的内 ...
- python gdal 矢量转栅格
data = gdal.Open(templateTifFileName, gdalconst.GA_ReadOnly)geo_transform = data.GetGeoTransform()x_ ...
- 服务器端 CentOS 下配置 JDK 和 Tonmcat 踩坑合集
一.配置 JDK 时,在 /etc/profile 文件下配置环境变量,添加 #java environment export JAVA_HOME=/usr/java/jdk- export CL ...
- JS高级——apply与call
上下文调用模式 可以修改this的值,也就是可以修改函数的调用方式,apply.call可以修改函数调用上下文,也就是this的值 <script> var name = "莱昂 ...
- git使用原理
如果需要新建仓库: mkdir new_artcle//artcle为文件名 cd new_artcle//进入该目录 git init //初始化工作空间 git add 文件名(article) ...