Codeforces 582B Once Again
http://codeforces.com/contest/582/problem/B
题目大意:给出一个序列,是由一个长度为n的序列复制T次得到的,问最长非下降子序列的长度。
思路:我们建立一个n*n的矩阵,a[i][j]代表第一段以i为末尾,第二段以j为末尾,拼接起来能增加多少长度,这样只要有一个空的矩阵c,我们让c乘上a^t,记住,这里的乘里面是:c[i][j]=max(c[i][j],a[i][k]*b[k][j]),略微和其他的矩乘不同。然后c里面元素最大那个就是答案。
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<iostream>
template<typename T>
class mx {
public:
T r[][];
int n;
public:
mx<T>(int _n):n(_n){}
mx<T>():n(){}
};
int n,T,b[];
int read(){
int t=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
template<typename T>
mx<T> operator *(mx<T> a,mx<T> b){
mx<T> c;
c.n=a.n;
for (int i=;i<=a.n;i++)
for (int j=;j<=a.n;j++)
c.r[i][j]=-;
for (int i=;i<=a.n;i++)
for (int j=;j<=a.n;j++)
for (int k=;k<=a.n;k++)
c.r[i][j]=std::max(c.r[i][j],a.r[i][k]+b.r[k][j]);
return c;
}
int main(){
n=read();T=read();
for (int i=;i<=n;i++)
for (int j=;j<=n;j++)
a.r[i][j]=c.r[i][j]=;
for (int i=;i<=n;i++) b[i]=read();
for (int i=;i<=n;i++)
for (int j=;j<=n;j++)
if (b[i]<=b[j]) {
a.r[i][j]=;
for (int k=;k<j;k++)
if (b[k]<=b[j])
a.r[i][j]=std::max(a.r[i][j],a.r[i][k]+);
}else a.r[i][j]=-;
a.n=n;
c.n=n;
while (T){
if (T%) c=c*a;
T/=;
a=a*a;
}
int ans=;
for (int i=;i<=n;i++)
for (int j=;j<=n;j++)
ans=std::max(ans,c.r[i][j]);
printf("%d\n",ans);
return ;
}
Codeforces 582B Once Again的更多相关文章
- 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. 2) D 582B Once Again...(快速幂)
A[i][j]表示在循环节下标i开头j结尾的最长不减子序列,这个序列的长度为p,另外一个长度为q的序列对应的矩阵为B[i][j], 将两序列合并,新的序列对应矩阵C[i][j] = max(A[i][ ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
随机推荐
- Unity欢迎窗口的信息
1.Video Tutorials提供Unity相关的教程,包括用户手册.组件手册以及脚本手册等内容.2.Unity Basics提供Unity的基础知识,例如操作界面.工作流程.发布设置等内容.3. ...
- 用Altium designer画PCB的一般心得
一.电路版设计的先期工作 1.利用原理图设计工具绘制原理图,并且生成对应的网络表.当然,有些特殊情况下,如电路版比较简单,已经有了网络表等情况下也可以不进行原理图的设计,直接进入PCB设计系统,在PC ...
- zabbix 对于logstash告警连续发邮件
打上勾就行
- op+3g
https://forum.openwrt.org/viewtopic.php?id=44895 http://eko.one.pl/forum/viewtopic.php?id=10269 http ...
- phpmyadmin导入大量数据比较快的做法
在一次项目在其他机器上配置的时候,将数据库以.sql的形式导出后,在新的机器上想将数据重新导入phpmyadmin的时候.按照以前的在数据库中将所有数据复制过来然后点击sql运行给卡住了(数据量过大) ...
- win10 iis 创建新站点注意事项
新建站点时:注意文件夹权限增加everyone. 快速打开IIS:win+r:inetmgr
- 在CentOS/RHEL 6.5上安装Chromium 谷歌浏览器
之前Google就说了,由于CentOS/RHEL 6已经是过期的系统,所以不再会有Chrome了. 虽然后来由于引起了社区的抗议,从而改口,不再提CentOS/RHEL 6是过期系统了:但是,目前在 ...
- VS2012/2013编辑器问题
1. Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality 解决办法:http://weblog.west-w ...
- 马士兵 Servlet_JSP(2) JSP源代码)
1.最简单的JSP HelloWorld.jsp <html> <head> <title>Hello</title> ...
- mysql插入数据时,中文乱码
MySQL 插入数据时,中文乱码问题的解决(转) 当向 MySQL 数据库插入一条带有中文的数据形如 insert into employee values(null,'张三','female','1 ...