Problem

题目链接

Solution

吼题啊吼题!

首先如何求本质不同的子序列个数就是 \(f[val[i]]=1+\sum\limits_{j=1}^k f[j]\)

其中 \(f[i]\) 表示的是以 \(i\) 结尾的子序列个数

先把原数列的不同子序列个数求出来,然后观察一下这个转移,贪心的发现每次都是选一个最早出现的 \(i\) 填到序列末尾,然后更新这个值。

所以填的部分一定是 \(\frac mk\) 个 \(K\) 的排列,还有多出来了 \(m\%k\) 个元素暴力填进去。

每 \(K\) 个元素的转移是一样的,可以拿矩乘做。然后多余的部分求前缀积暴力求就行了。

Code

#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<cctype>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using std::min;
using std::max;
using std::swap;
using std::vector;
const int N=105;
const int M=1e6+5;
typedef double db;
typedef long long ll;
#define int long long
const int mod=1e9+7;
#define pb(A) push_back(A)
#define pii std::pair<int,int>
#define mp(A,B) std::make_pair(A,B) int n,m,k,per[M];
int val[M];pii las[M]; struct Mat{
int a[N][N]; void clear(){
memset(a,0,sizeof a);
} void init(){
clear();
for(int i=1;i<=k+1;i++)
a[i][i]=1;
} void print(){
for(int i=1;i<=k+1;i++,puts(""))
for(int j=1;j<=k+1;j++)
printf("%lld ",a[i][j]);
} friend Mat operator*(Mat x,Mat y){
Mat z;z.clear();
for(int i=1;i<=k+1;i++){
for(int p=1;p<=k+1;p++){
for(int j=1;j<=k+1;j++)
z.a[i][j]=(z.a[i][j]+x.a[i][p]*y.a[p][j]%mod)%mod;
}
} return z;
}
}cs,f,qzh[N]; int getint(){
int X=0,w=0;char ch=0;
while(!isdigit(ch))w|=ch=='-',ch=getchar();
while( isdigit(ch))X=X*10+ch-48,ch=getchar();
if(w) return -X;return X;
} Mat ksm(Mat x,int y){
Mat ans;ans.init();
while(y){
if(y&1) ans=ans*x;
x=x*x;y>>=1;
} return ans;
} signed main(){
freopen("sequence.in","r",stdin);freopen("sequence.out","w",stdout);
n=getint(),m=getint(),k=getint();
int sum=0;f.clear();f.a[1][k+1]=1;
for(int i=1;i<=k;i++) las[i]=mp(0,i);
for(int i=1;i<=n;i++){
val[i]=getint();
int p=f.a[1][val[i]];
f.a[1][val[i]]=(sum+1)%mod;
sum-=p;sum+=f.a[1][val[i]];sum%=mod;
las[val[i]]=mp(i,val[i]);
} std::sort(las+1,las+1+k);
qzh[0].init();
for(int i=1;i<=k;i++){
per[i]=las[i].second;
qzh[i].clear();
for(int j=1;j<=k+1;j++) qzh[i].a[j][j]=1;
for(int j=1;j<=k+1;j++) qzh[i].a[j][per[i]]=1;
qzh[i]=qzh[i-1]*qzh[i];
} cs=ksm(qzh[k],m/k);
cs=cs*qzh[m%k];
f=f*cs;int ans=0;
for(int i=1;i<=k;i++) (ans+=f.a[1][i])%=mod;
printf("%lld\n",ans);
return 0;
}

[JZOJ5836] Sequence的更多相关文章

  1. oracle SEQUENCE 创建, 修改,删除

    oracle创建序列化: CREATE SEQUENCE seq_itv_collection            INCREMENT BY 1  -- 每次加几个              STA ...

  2. Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等

    功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...

  3. DG gap sequence修复一例

    环境:Oracle 11.2.0.4 DG 故障现象: 客户在备库告警日志中发现GAP sequence提示信息: Mon Nov 21 09:53:29 2016 Media Recovery Wa ...

  4. Permutation Sequence

    The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  5. [LeetCode] Sequence Reconstruction 序列重建

    Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...

  6. [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列

    Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...

  7. [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 ...

  8. [LeetCode] Longest Consecutive Sequence 求最长连续序列

    Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...

  9. [LeetCode] Permutation Sequence 序列排序

    The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

随机推荐

  1. SpringMvc在返回数据之前进行统一处理

    这里其实有多种解决方案 如果你不需要获取request对象 可以采用aop(环绕通知)的方式来统一修改 如果你需要获取request对象,那么就需要采用下面的方式 0自己定义一个注解,内容如下 @Ta ...

  2. CSS3美化网页!!

    一.span标签:能让某几个文字或者某个词语凸显出来        <p>           今天是11月份的<span>第一天</span>,地铁卡不打折了  ...

  3. 关于java poi itext生成pdf文件的例子以及方法

    最近正在做导出pdf文件的功能,所以查了了一些相关资料,发现不是很完善,这里做一些小小的感想,欢迎各位“猿”童鞋批评指正. poi+itext,所需要的jar包有itext-2.1.7.jar,poi ...

  4. ABP框架系列之五:(Unit Of Work-工作单元)

    Introduction Connection and transaction management is one of the most important concepts in an appli ...

  5. 卷积(转自wiki百科)

    维基百科,自由的百科全书 图示两个方形脉冲波的卷积.其中函数 "g" 首先对  反射,接着平移 "t" ,成为  .那么重叠部份的面积就相当于 "t& ...

  6. IDEA运行android项目一直是同一个apk

    1.IDEA运行android项目时不像eclipse和android studio那样直接运行,IDEA需要设置Artifacts,这样每次运行的时候它才能重新编译,以下附上步骤! 这样就可以了.

  7. Integer Array Ladder questions

    1.这个题不难,关键在于把题目意思理解好了.这个题问的不清楚.要求return new length,很容易晕掉.其实就是return 有多少个单独的数. import java.util.Array ...

  8. requests应用

    一.简介 什么是requests模块: requests模块是python中原生的基于网络请求的模块,其主要作用是用来模拟浏览器发起请求.功能强大,用法简洁高效.在爬虫领域中占据着半壁江山的地位. 为 ...

  9. Android开发工程师文集-提示框,菜单,数据存储,组件篇

    提示框,菜单,数据存储,组件篇 Toast Toast.makeText(context, text, 时间).show(); setDuration();//设置时间 setGravity();// ...

  10. ElasticSearch权威指南学习(结构化查询)

    请求体查询 简单查询语句(lite)是一种有效的命令行adhoc查询.但是,如果你想要善用搜索,你必须使用请求体查询(request body search)API. 空查询 我们以最简单的 sear ...