题目

预处理转移矩阵的\(2^k\)。

然后把关键点按下标排序。

每次用类似于矩阵快速幂的方法求出两个关键点中间的转移矩阵。

#include<bits/stdc++.h>
using namespace std;
const int N=107,P=1000000007;
int read(){int x=0,c=getchar();while(!isdigit(c))c=getchar();while(isdigit(c))x=x*10+c-48,c=getchar();return x;}
int inc(int a,int b){a+=b;return a>=P? a-P:a;}
int mul(int a,int b){return 1ll*a*b%P;}
int max(int a,int b){return a>b? a:b;}
int n,m,q,lim,t,f[N],c[N],C[N];
struct node{int n,t,c[N];}p[N];
int operator<(node a,node b){return a.n<b.n;}
struct mat
{
int a[N][N],n,m;
int*operator[](int x){return a[x];}
void clear(){memset(a,0,sizeof a);}
void init(){clear();for(int i=1;i<=n;++i)a[i][i]=1;}
}A[31],F;
mat operator*(mat a,mat b)
{
mat c;c.clear(),c.n=a.n,c.m=b.m;int i,j,k;
for(i=1;i<=a.n;++i) for(j=1;j<=b.m;++j) for(k=1;k<=a.m;++k) c[i][j]=inc(c[i][j],mul(a[i][k],b[k][j]));
return c;
}
void init()
{
A[0].clear(),F.clear(),A[0].n=A[0].m=F.m=lim,F.n=1;int i,j;
for(i=1;i<A[0].n;++i) A[0][i][i+1]=1;
for(i=1;i<=t;++i) A[0][i][1]=c[i-1];
for(i=1;1<<i<=n;++i) A[i]=A[i-1]*A[i-1];
for(i=1,j=m;i<=lim&&j;++i,--j) F[1][i]=f[j];
}
void power(int k){for(int i=0;i<31;++i)if(k&1<<i)F=F*A[i];}
int main()
{
int T=0,i,j,now,ans;
while(scanf("%d%d%d",&n,&m,&q)!=EOF)
{
for(i=1;i<=m;++i) f[i]=read();
lim=t=read();
for(i=0;i<t;++i) c[i]=read();
for(i=1;i<=q;++i)
{
p[i].n=read(),p[i].t=read();
if(p[i].n<=n) lim=max(lim,p[i].t);
for(j=1;j<=p[i].t;++j) p[i].c[j]=read();
}
sort(p+1,p+q+1),init(),now=m;
for(i=1;i<=q;++i)
{
if(p[i].n<=now||p[i].n>n) continue;
for(j=1;j<=p[i].t;++j) C[j]=p[i].c[j];
power(p[i].n-now-1),now=p[i].n,ans=0;
for(j=1;j<=p[i].t;++j) ans=inc(ans,mul(C[j],F[1][j]));
for(j=lim;j^1;--j) F[1][j]=F[1][j-1];
F[1][1]=ans;
}
power(n-now),printf("Case %d: %d\n",++T,F[1][1]);
}
}

HDU4471 Homework的更多相关文章

  1. 【HDU4471】Homework(矩阵快速幂)

    [HDU4471]Homework(矩阵快速幂) 题面 Vjudge 给定一个数列的前\(m\)项,给定一个和前\(t\)项相关的递推式. 有\(q\)个位置的递推式单独给出,求数列第\(n\)项. ...

  2. bzoj 4320: ShangHai2006 Homework

    4320: ShangHai2006 Homework Time Limit: 10 Sec Memory Limit: 128 MB Description 1:在人物集合 S 中加入一个新的程序员 ...

  3. HDU 1789 Doing Homework again(贪心)

    Doing Homework again 这只是一道简单的贪心,但想不到的话,真的好难,我就想不到,最后还是看的题解 [题目链接]Doing Homework again [题目类型]贪心 & ...

  4. hdu-1789-Doing Homework again

    /* Doing Homework again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...

  5. HDU 1789 Doing Homework again (贪心)

    Doing Homework again http://acm.hdu.edu.cn/showproblem.php?pid=1789 Problem Description Ignatius has ...

  6. Doing Homework 状态压缩DP

    Doing Homework 题目抽象:给出n个task的name,deadline,need.  每个任务的罚时penalty=finish-deadline;   task不可以同时做.问按怎样的 ...

  7. 机器学习 —— 概率图模型(Homework: Exact Inference)

    在前三周的作业中,我构造了概率图模型并调用第三方的求解器对器进行了求解,最终获得了每个随机变量的分布(有向图),最大后验分布(双向图).本周作业的主要内容就是自行编写概率图模型的求解器.实际上,从根本 ...

  8. hdoj 1789 Doing Homework again

    Doing Homework again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  9. homework做了些什么?

    第一步:get_new_guid_uid_pairs_{$ymd} 参数是时间和100上的文件. 那么100上的文件是从哪里来的呢? 我们进入到100机器上,打开root权限下的cron,看到如下内容 ...

随机推荐

  1. 【leetcode】Valid Parenthesis String

    题目: Given a string containing only three types of characters: '(', ')' and '*', write a function to ...

  2. The Preliminary Contest for ICPC Asia Shanghai 2019 L. Digit sum

    题目:https://nanti.jisuanke.com/t/41422 思路:预处理 #include<bits/stdc++.h> using namespace std; ][]= ...

  3. linux常用的镜像(centos、kali、redhat等)官方下载地址

    常用的linux版本: Redhat:https://developers.redhat.com/topics/linux/ Centos:https://www.centos.org/downloa ...

  4. forEach、map、filter、reduce的区别

    1.相同点: 都会循环遍历数组中的每一项: map().forEach()和filter()方法里每次执行匿名函数都支持3个参数,参数分别是:当前元素.当前元素的索引.当前元素所属的数组: 匿名函数中 ...

  5. Windows 环境上域名配置

    1.Hosts位置 C:\Windows\System32\drivers\etc\hosts 2.Hosts内容 # Copyright (c) 1993-2009 Microsoft Corp. ...

  6. 2018百度之星初赛B轮 p1m2

    p1m2 Accepts: 954 Submissions: 4063 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/1310 ...

  7. 论文阅读:Stateless Network Functions: Breaking the Tight Coupling of State and Processing

    摘要: 无状态网络功能是一个新的网络功能虚拟化架构,解耦了现有的网络功能设计到无状态处理组件以及数据存储层,在打破紧密耦合的同时,实现了更具可伸缩性和可恢复性的网络功能基础设施.无状态NF处理实例是围 ...

  8. Win7,win10(部分机型) 安装appscan9.0.3.10(可升级)实操流程

    Win10部分机型不能很好的兼容appscan,建议使用者用win7系统安装appscan 写于:2018.12.2 IBM Security AppScan Standard 可通过自动执行应用安全 ...

  9. npm安装源修改为淘宝源

    npm安装源修改为淘宝源 标签(空格分隔): 编译 原:https://cnodejs.org/topic/4f9904f9407edba21468f31e npm安装源修改为淘宝源 镜像使用方法(三 ...

  10. C# DataTable 增加行与列

    亲测有用的方法 DataTable AllInfos = new DataTable();//生成一个表格 DataColumn typeColumn = new DataColumn();//建一个 ...