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的更多相关文章

  1. 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 ...

  2. 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][ ...

  3. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  4. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  5. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  6. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  7. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  8. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  9. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

随机推荐

  1. hdu 找新朋友

    #include <cstdio> #include <cstring> #include <algorithm> using namespace std; ]; ...

  2. ASM-51 宏汇编使用手册

    A51与ASM51基本相同   ASM-51 宏汇编主要用来开发Inter8051系列单片机,它具有宏处理,数据处理,列表处理和条件处理等多种功能.源程序的编写完全采用 Inter标准助记符和行格式. ...

  3. Qt在Windows下的三种编程环境搭建

    尊重作者,支持原创,如需转载,请附上原地址:http://blog.csdn.net/libaineu2004/article/details/17363165 从QT官网可以得知其支持的平台.编译器 ...

  4. Tracing JIT

    在一个从Java源码编译到JVM字节码的编译器(如javac.ECJ)里,一个“编译单元”(CompilationUnit)指的是一个Java源文件.而在Dalvik VM的JIT里也有一个结构体名为 ...

  5. js深入研究之无法理解的js类代码,extend扩展

    <script type="text/javascript"> function Person(name) { this.name = name; } Person.p ...

  6. js深入研究之Person类案例

    <script type="text/javascript"> /* 定义一个Person类 */ function Person(name, age) { this. ...

  7. Visual Studio 2012 编译C++显示cl命令

    为了用newlisp来实现VC编译,以便用我的Emacs开发VC程序,而不需要再打开VS 2012, 需要自己实现命令行的编译.我不需要nmake,因为我想直接了解VC编译器,以便今后更好的驾驭它. ...

  8. 马士兵 Servlet_JSP(3) Servlet和JSP的通信(源代码)

    (1)从JSP调用Servlet可用<jsp:forward>,请求信息自动转到Servlet FromJspToServlet.jsp <html>     <body ...

  9. MySQL查询当前数据上一条和下一条的记录

    如果ID是主键或者有索引,可以直接查找: 方法一: 查询上一条记录的SQL语句(如果有其他的查询条件记得加上other_conditions以免出现不必要的错误): ) [and other_cond ...

  10. loadrunner java 缺少必要的导入包报错

    loadrunner 运行从eclipse中做好的脚本,ctrl + A 复制到loadrunner中来, 添加参数化的的语句:verifyCode =    lr.eval_string (&quo ...