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 ...
随机推荐
- window下安装composer步骤(linux待研究)
window下安装composer步骤--注意(安装完之后需要重启电脑才能生效) 转发:https://blog.csdn.net/wengedexiaozao/article/details/798 ...
- Solr 6.7学习笔记(02)-- 配置文件 managed-schema (schema.xml) -- 样例(6)
managed-schema 样例: <?xml version="1.0" encoding="UTF-8" ?> <!-- License ...
- 安装篇:MySQL系列之一
环境:CentOS6.9系统安装MariaDB-10.2.15 一.yum包管理器安装MariaDB-server 1)配置yum源(MariaDB官方源) [root@centos6 ~]# v ...
- html_entity_decode与htmlentities函数
htmlentities() 函数把字符转换为 HTML 实体.html_entity_decode() 函数把 HTML 实体转换为字符.例子:$a = '<div> <p> ...
- Age of Moyu (2018 Multi-University Training Contest 7)
题目链接 #include <bits/stdc++.h> using namespace std; typedef long long ll; inline ll read(){ ,f= ...
- Asp.net Core 创建控制器时出错问题记录(运行所选代码生成器时出错)
问题描述:在创建一个MVC控制器(带读写,使用EF) 解决方法:添加nuget包
- Linux--6 redis订阅发布、持久化、集群cluster、nginx入门
一.redis发布订阅 Redis 通过 PUBLISH .SUBSCRIBE 等命令实现了订阅与发布模式. 其实从Pub/Sub的机制来看,它更像是一个广播系统,多个Subscriber可以订阅多个 ...
- 用servlet获取IP等信息
Locale languageType=request.getLocale();//获取用户语言 String localIp=request.getLocalAddr();//获取本地ip int ...
- PartTime__学习辅助软件_20161025
1.http://www.680.com/ruanjian/412629.html 1.1.http://www.gysjxjy.com/ 密码:我的名字的拼音(全小写) 使用的身份证信息:http: ...
- 【hihocoder】1237 : Farthest Point 微软2016校招在线笔试题
题目:给定一个圆,要你求出一个在里面或者在边上的整数点,使得这个点到原点的距离最大,如果有多个相同,输出x最大,再输出y最大. 思路:对于一个圆,里面整点个数的x是能确定的.你找到x的上下界就可以了. ...