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. [转]SE43 修改SAP标准菜单、登陆界面、背景图片

    1.事务码se43 复制标准菜单S000 到 ZS000  2.按实际需要修改 ZS000  3.在事务码SSM2中用ZS000 代替 S000  4.注销后重新登陆 o 修改SAP登陆界面(在本博客 ...

  2. Python小世界:项目虚拟环境配置的N种方法

    前言 和其他大多数现代编程语言一样,Python对包和 模块的下载.存储以及管理有其自己的一套方法.但是当我们同时开发多个项目工程的时候,不同的项目会将第三方的包存放在相同的路径下.这就意味着,如果有 ...

  3. kuangbin专题十二 HDU1029 Ignatius and the Princess IV (水题)

    Ignatius and the Princess IV Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32767 K ( ...

  4. Codeforces Round #501 (Div. 3) 1015D Walking Between Houses

    D. Walking Between Houses time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  5. CMD当前代码页修改

    python3.x在程序开发中统一的编码是 UTF-8,但是进行交互式编程的时候会经常遇到乱码问题,这是因为Window cmd的默认编码是GBK.与程序采用的 UTF-8 不一致造成的中文及特殊字符 ...

  6. Python 列表list 和 字符串str 互转

    一.列表list转字符串str 命令(python2.x):''.join(list) 命令(python2.x):''.join(str(s) for s in list) 其中,引号中是字符之间的 ...

  7. new与malloc区别

    1.new分配内存时会按照数据类型计算需要分配内存的大小,malloc分配内存时是按照指定的大小分配的:2.new不仅分配一段内存,而且会调用构造函数,malloc不会调用构造函数:之前看到过一个题说 ...

  8. SpringBoot | 第二十三章:日志管理之整合篇

    前言 在本系列<第四章:日志管理>中,由于工作中日志这块都是走默认配置,也没有深入了解过,因为部署过程中直接使用了linux中的输出重定向功能,如java -jar xx.jar > ...

  9. Freetype 安装时提示 make: Nothing to be done for `unix'

    [Software-Freetype] Freetype 安装时提示 make: Nothing to be done for `unix' 官网下载的第三方软件包,编译安装会报以下错误,解决办法如下 ...

  10. Java hibernate 遇到的问题:could not read a hi value

    问题: 解决办法:在网上看到一篇文章说是把数据库实体类的注解@GeneratedValue改成@GeneratedValue(strategy = GenerationType.IDENTITY) , ...