Codeforces Round #323 (Div. 2) D 582B Once Again...(快速幂)
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...(快速幂)的更多相关文章
- 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 ...
- Codeforces Round #518 (Div. 1) Computer Game 倍增+矩阵快速幂
接近于死亡的选手没有水平更博客,所以现在每五个月更一篇. 这道题呢,首先如果已经有权限升级了,那么后面肯定全部选的是 \(p_ib_i\) 最高的. 设这个值为 \(M=\max \limits_i ...
- 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 ...
- 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 ...
- 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 ...
- 重复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, . ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- SQL Server 2012安装——.net framework 3.5离线安装
前言 电脑用着一直很不舒服,所以就决定对电脑重新配置一番,在装数据库这里,可谓是屡装屡败.自己感觉太麻烦了,于是每次数据库装失败后,就重装系统,然后配置上网文档,这样一来,弄得自己挺恶心,这次很明显成 ...
- Filter的使用及其生命周期介绍
一.Filter 1. Filter简介 > Filter翻译为中文是过滤器的意思. > Filter是JavaWeb的三大web组件之一:Servlet.Filter.Listener ...
- 最全 MySQL 优化方法,从此优化不再难
说起MySQL的查询优化,相信大家收藏了一堆奇技淫巧:不能使用SELECT *.不使用NULL字段.合理创建索引.为字段选择合适的数据类型..... 你是否真的理解这些优化技巧?是否理解其背后的工作原 ...
- Meter - 连续性能测试 - JMeter + ANT + Jenkins集成 - 第1部分
目标: 创建包含性能测试流程的持续交付管道, 以尽早检测任何与性能相关的问题. 通常,全面的性能测试将在分段/预生产环境中完成,该环境可能与您的生产环境相同.在完成QA功能/回归验证后,将代码推送到分 ...
- Python 2.x和3.x不同点
1.print和print() 2.yield 出现下面的错误Traceback (most recent call last): File “<pyshell#32>”, line 1, ...
- 64位wampserver开启curl扩展失败的问题
今天在运行程序时报错: Fatal error:Call to undefined function curl_init()... 在网上查了一下,是因为php_curl.dll扩展没有开启的缘故,于 ...
- JAVA实现向文本文件中多次写入数据
使用这种方式,当指定的文件不存在时会自动创建. //此处设置为true即可追加 FileWriter out = new FileWriter("D:\\1.txt",true); ...
- java中key值可以重复的map:IdentityHashMap
在Java中,有一种key值可以重复的map,就是IdentityHashMap.在IdentityHashMap中,判断两个键值k1和 k2相等的条件是 k1 == k2 .在正常的Map 实现(如 ...
- mysql存储方式MyISAM 和 InnoDB的区别
MyISAM 和 InnoDB 讲解: InnoDB和MyISAM是许多人在使用MySQL时最常用的两个表类型,这两个表类型各有优劣,视具体应用而定.基本的差别为:MyISAM类型不支持事务处理等高级 ...
- C#数据库(MSSQL)帮助类
/// <summary> /// 数据库帮助类 /// <author>Devin</author> /// </summary> public se ...