A[i][j]表示在循环节下标i开头j结尾的最长不减子序列,这个序列的长度为p,另外一个长度为q的序列对应的矩阵为B[i][j],

将两序列合并,新的序列对应矩阵C[i][j] = max(A[i][k]+B[k][j])。非法的情况标记为-INF,用倍增加速。

#include<bits/stdc++.h>
using namespace std; const int INF = 0x3f3f3f3f;
const int maxn = ;
int n;
typedef int MType;
struct Matrix
{
MType dat[maxn][maxn];
MType *operator [](int x){ return dat[x]; }
Matrix operator | (Matrix& B) {
Matrix re;
for(int i = ; i < n; i++){
for(int j = ; j < n; j++){
re[i][j] = -INF;
for(int k = ; k < n; k++){
re[i][j] = max(re[i][j],dat[i][k]+B[k][j]);
}
}
}
return re;
}
Matrix operator ^ (int q){
Matrix Re, A = *this;
memset(Re.dat,,sizeof(Re.dat));
while(q){
if(q&){
Re = Re | A;
}
A = A | A;
q >>= ;
}
return Re;
}
}; int a[maxn]; //#define LOCAL
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
int T; scanf("%d%d",&n,&T);
for(int i = ; i < n; i++){
scanf("%d",a+i);
} Matrix A;
for(int i = ; i < n; i++){
for(int j = ; j < n; j++){
if(a[i]>a[j] ) A[i][j] = -INF;
else {
A[i][j] = ;
for(int k = ; k < j; k++){
if(a[k] <= a[j])
A[i][j] = max(A[i][j],A[i][k]+);
}
}
}
}
A = A^T;
int ans = ;
for(int i = ; i < n;i++){
for(int j = ; j < n; j++){
ans = max(ans,A[i][j]);
}
}
printf("%d\n",ans);
return ;
}

Codeforces Round #323 (Div. 2) D 582B Once Again...(快速幂)的更多相关文章

  1. Codeforces Round #324 (Div. 2) B. Kolya and Tanya 快速幂

    B. Kolya and Tanya Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/pro ...

  2. Codeforces Round #518 (Div. 1) Computer Game 倍增+矩阵快速幂

    接近于死亡的选手没有水平更博客,所以现在每五个月更一篇. 这道题呢,首先如果已经有权限升级了,那么后面肯定全部选的是 \(p_ib_i\) 最高的. 设这个值为 \(M=\max \limits_i ...

  3. Codeforces Round #323 (Div. 2) Once Again... CodeForces - 582B 最长非下降子序列【dp】(不明白)

    B. Once Again... time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  4. Codeforces Round #323 (Div. 1) B. Once Again... 暴力

    B. Once Again... Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/582/probl ...

  5. Codeforces Round #323 (Div. 2) C. GCD Table 暴力

    C. GCD Table Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/583/problem/C ...

  6. 重复T次的LIS的dp Codeforces Round #323 (Div. 2) D

    http://codeforces.com/contest/583/problem/D 原题:You are given an array of positive integers a1, a2, . ...

  7. Codeforces Round #323 (Div. 2) D. Once Again... 乱搞+LIS

    D. Once Again... time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  8. Codeforces Round #323 (Div. 2) C. GCD Table map

    题目链接:http://codeforces.com/contest/583/problem/C C. GCD Table time limit per test 2 seconds memory l ...

  9. Codeforces Round #323 (Div. 2) C.GCD Table

    C. GCD Table The GCD table G of size n × n for an array of positive integers a of length n is define ...

随机推荐

  1. Linux之shell备份数据库

    功能概述: 使用shell脚本对服务器的数据库(全部或指定数据库)进行备份.对15天(固定天数)之前的数据库备份进行删除 命令实现: 待定

  2. Codeforces Round #522 Div2C(思维)

    #include<bits/stdc++.h>using namespace std;int a[200007];int b[200007][7];int ans[200007];int ...

  3. c# Relative Path convert to Absolute Path

    Reference: http://stackoverflow.com/questions/4796254/relative-path-to-absolute-path-in-c http://sta ...

  4. MCP|MZL|Accurate Estimation of Context- Dependent False Discovery Rates in Top- Down Proteomics 在自顶向下蛋白组学中精确设定评估条件估计假阳性

    一. 概述: 自顶向下的蛋白质组学技术近年来也发展成为高通量蛋白定性定量手段.该技术可以在一次的实验中定性上千种蛋白,然而缺乏一个可靠的假阳性控制方法阻碍了该技术的发展.在大规模流程化的假阳性控制手段 ...

  5. iPhone摄影中的深度捕捉(WWDC2017-Session 507)

    507是深度媒体相关的概念层面的内容.主要为下面4个部分: Depth and disparity on iPhone 7 Plus Streaming depth data from the cam ...

  6. 自制Java虚拟机(四)-对象、new、invokespecial

    自制Java虚拟机(四)-对象.new.invokespecial 一.对象的表示 刚开始学Java的时候,图书馆各种教程,书名往往都是“Java面向对象高级编程”,通常作者都会与C++做个比较,列出 ...

  7. print和sys.stdout

    print print语句执行的操作是一个写操作,把我们从外设输入的数据写到了stdout流,并进行了一些特定的格式化.和文件方法不同,在执行打印操作是,不需要将对象转换为字符串(print已经帮我们 ...

  8. 洛谷P4018 Roy&October之取石子

    题目背景 \(Roy\)和\(October\)两人在玩一个取石子的游戏. 题目描述 游戏规则是这样的:共有\(n\)个石子,两人每次都只能取\(p^k\)个(\(p\)为质数,\(k\)为自然数,且 ...

  9. POJ1023 The Fun Number System

    题目来源:http://poj.org/problem?id=1023 题目大意: 有一种有趣的数字系统.类似于我们熟知的二进制,区别是每一位的权重有正有负.(低位至高位编号0->k,第i位的权 ...

  10. 5、kvm快照相关操作

    kvm虚拟机默认使用raw格式的镜像格式,性能最好,速度最快,不支持支持镜像,zlib磁盘压缩,AES加密等.要使用镜像功能,但是磁盘格式为qcow2就是支持. 关闭虚拟机 virsh shutdow ...