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. PowerShell正则表达式(一) 定义模式

    PowerShell正则表达式(一) 定义模式 7 29 9月, 2013  在 Powershell tagged 正则表达式 by Mooser Lee 本文索引 [隐藏] 1限定符 2识别IP地 ...

  2. Powershell ForEach-Object 循环

    Powershell管道就像流水线,对于数据的处理是一个环节接着一个环节,如果你想在某一环节对流进来的数据逐个细致化的处理,可是使用ForEach-Object,$_ 代表当前的数据. 对管道对象逐个 ...

  3. 【Xamarin 开发 IOS --IOS ViewController生命周期】

    ViewController ViewController是IOS开发中MVC模式中的C,ViewController是view的controller,ViewController的职责主要包括管理内 ...

  4. sql中update,alter,modify,delete,drop的区别和使用(整理)(转)

    关于update和alter: 百度知道上关于update和alter有一个很形象的总结: 一个表有很多字段,一个字段里有很多数据. 一个家有很多房间,一个房间里有很多家具. update是用来将衣柜 ...

  5. 微软CEO史蒂夫·鲍尔默(Steve Ballmer)在12个月内退休

    Microsoft CEO Steve Ballmer to retire within 12 months Aug. 23, 2013 Board of directors initiates su ...

  6. CSDN第四届在线编程大赛2014初赛:带通配符的数

    题目要求: 输入参数:参数A,含有任意个数的?的数值字符串,如:12?4,?代表一位任意数             参数B,不含?的数值字符串,长度与参数A一致输出结果:参数A比参数B大的可能数值个数 ...

  7. MVC MVC 路由详解

    在项目中我们引用了System.Web.Routing;   Routing的作用: 确定Controller 确定Action 确定其他参数 根据识别出来的数据, 将请求传递给Controller和 ...

  8. BoneCP学习笔记

    什么是BoneCP BoneCP 是一个快速.免费而且开源的java数据库连接池(JDBC Pool)管理工具库.如果你曾经使用过C3P0或者DBCP,那你肯定知道上面这句话的意思:如果你没用过这些, ...

  9. 实现jquery EasyUI tabs选项卡关闭图标后载入自己定义事件

    当关闭tabs选项卡时,底部footer须要通过javascript又一次定位calcFooter(),怎样实现呢?选项卡上的关闭图标的方法是easyui自带的,calcFooter()写在onClo ...

  10. JMeter简单的性能测试实例

    JMeter基础之——一个简单的性能测试 我们了解了jmeter的一此主要元件,那么这些元件如何使用到性能测试中呢.这一节创建一个简单的测试计划来使用这些元件.该计划对应的测试需求. 1)测试目标网站 ...