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 ...
随机推荐
- 如何使用ros命令行显示图片
rosrun image_view image_view image:=[TOPIC] 注意:每次只能显示一个UI.不能在一条命令中订阅多个节点.
- CodeForces 110C 【构造】
思路: 7越多越好,然后从7最多个数枚举过去,判断一下剩下的能不能用4解决就好了: #include <bits/stdc++.h> using namespace std; typede ...
- 洛谷P3146 [USACO16OPEN]248
P3146 [USACO16OPEN]248 题目描述 Bessie likes downloading games to play on her cell phone, even though sh ...
- ubuntu设置nginx为系统服务
ubuntu设置nginx为系统服务,如果没有设置为系统服务,无法执行 sudo service nginx startsudo service nginx stop 设置为系统服务命令 sudo u ...
- Eclipse设置代码模板Code Template
团队协作最好是使用相同的代码模板 Code Template,打开 Window -> Preference -> Java -> Code Style -> Code Tem ...
- python_魔法方法(三):__str__()和__repr__()
使用python的魔法方法和time模块定制一个计时器的类 1.用time模块里的localtime()方法获取时间2.time.localtime返回struct_time格式3.表现你的类:__s ...
- bzoj 3732: Network 树上两点边权最值
http://www.lydsy.com/JudgeOnline/problem.php?id=3732 首先想到,要使得最长边最短,应该尽量走最短的边,在MST上. 然后像LCA那样倍增娶个最大值 ...
- Java多线程与并发——生产者与消费者应用案例
多线程的开发中有一个最经典的操作案例,就是生产者-消费者,生产者不断生产产品,消费者不断取走产品. package com.vince; /** * 生产者与消费者案例 * @author Admin ...
- (转)linux正则表达式详解
linux正则表达式详解 http://blog.csdn.net/wuliowen/article/details/64131815 1:什么是正则表达式: 简单的说,正则表达式就是处理字符串的方法 ...
- Sqoop架构
Sqoop 架构 Sqoop 架构是非常简单的,它主要由三个部分组成:Sqoop client.HDFS/HBase/Hive.Database.下面我们来看一下 Sqoop 的架构图. 用户向 Sq ...