B. Once Again...

Time Limit: 1 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/582/problem/B

Description

You are given an array of positive integers a1, a2, ..., an × T of length n × T. We know that for any i > n it is true that ai = ai - n. Find the length of the longest non-decreasing sequence of the given array.

Input

The first line contains two space-separated integers: n, T (1 ≤ n ≤ 100, 1 ≤ T ≤ 107). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 300).

Output

Print a single number — the length of a sought sequence.

Sample Input

4 3
3 1 4 2

Sample Output

5

HINT

题意

给你一个n*t这么长的序列,然后求最长不递减序列

其中a[i+n]=a[i]

题解:

暴力,如果t<=300,我们就直接暴力求就好了

如果t>的话,我们就大胆猜测,中间肯定是连续选一个数

那么我们就预处理前面以a[i]开始的最长,和后面的以a[i]最长是啥就好了~

代码:

#include<iostream>
#include<stdio.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
using namespace std; #define maxn 3225020 int a[maxn];
int dp1[maxn];
int dp2[maxn];
int dp3[maxn];
int lis[maxn]; int main()
{
int n,t;scanf("%d%d",&n,&t);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
if(t<=)
{
int ans = ;
for(int i=;i<=n;i++)
for(int j=;j<t;j++)
a[j*n+i] = a[i];
for(int i=;i<=n*t;i++)
{
lis[i]=;
for(int j=;j<i;j++)
if(a[i]>=a[j])
lis[i]=max(lis[i],lis[j]+);
ans = max(lis[i],ans);
}
printf("%d\n",ans);
return ;
}
int k = ;
for(int i=;i<=n;i++)
dp2[a[i]]++;
for(int i=;i<=n;i++)
for(int j=;j<=k;j++)
a[j*n+i] = a[i]; for(int i=;i<=k*n;i++)
{
lis[i]=;
for(int j=;j<i;j++)
if(a[i]>=a[j])
lis[i]=max(lis[i],lis[j]+);
dp1[a[i]] = max(dp1[a[i]],lis[i]);
} memset(lis,,sizeof(lis)); reverse(a+,a++k*n);
for(int i=;i<=k*n;i++)
{
lis[i]=;
for(int j=;j<i;j++)
if(a[i]<=a[j])
lis[i]=max(lis[i],lis[j]+);
dp3[a[i]] = max(dp3[a[i]],lis[i]);
} int ans = ;
for(int i=;i<=;i++)
for(int j=i;j<=;j++)
for(int m=j;m<=;m++)
ans = max(dp1[i]+dp2[j]*(t-*k)+dp3[m],ans);
printf("%d\n",ans);
}

Codeforces Round #323 (Div. 1) B. Once Again... 暴力的更多相关文章

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

  2. Codeforces Round #323 (Div. 2) B 贪心,暴力

    B. Robot's Task time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  3. Codeforces Round #323 (Div. 2) D. Once Again... 暴力+最长非递减子序列

                                                                                  D. Once Again... You a ...

  4. 重复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, . ...

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

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

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

  8. Codeforces Round #323 (Div. 1) A. GCD Table

    A. GCD Table time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  9. Codeforces Round #323 (Div. 2) E - Superior Periodic Subarrays

    E - Superior Periodic Subarrays 好难的一题啊... 这个博客讲的很好,搬运一下. https://blog.csdn.net/thy_asdf/article/deta ...

随机推荐

  1. UVA 1324 The Largest Clique 最大团(强连通分量,变形)

    题意:给一个有向图,要求找出一些点,使得这些点中的任意点对,要么可以互通,要么单向可达. 思路:最低只要求单向可达即可,即a->b都可以算进去. 强连通分量内的点肯定是满足要求的,可以全选,但是 ...

  2. 让Codeigniter控制器支持多级目录

    <?php if (!defined('BASEPATH')) { exit ('No direct script access allowed');} class MY_Router exte ...

  3. MD5加密帮助类

    using System; using System.Collections.Generic; using System.Text; namespace AIMSCommon { /// <su ...

  4. HDU2859 Phalanx 简单DP

    dp[i][j]代表以s[i][j]字符为右上角的最大对称方阵的尺寸 最左边那一列都为1,然后按列更新,代码实现比较简单,感觉有点卡时间,如果对称度很好,时间应该比较高,我只会这种了 #include ...

  5. Clone PDB from same CDB

    Clone PDB 用途: 1.用于测试,从生产系统clone数据来进行测试 2.诊断性能问题   Clone PDB Using OMF from same CDB 环境信息: DB Version ...

  6. [BILL WEI]SQL 存储过程学习

    --查看数据库exec sp_databases ;--查看表exec sp_tables ;--查看列exec sp_columns WMS_ASN;--查看索引exec sp_helpindex ...

  7. 【转】修改xampp的mysql默认密码

    http://www.cnblogs.com/hongchenok/archive/2012/08/21/2648549.html MySQL 的“root”用户默认状态是没有密码的,所以在 PHP ...

  8. js特效第九天

    offset家族(获取元素尺寸) offsetWidth得到对象的宽度,自己的,与他人无关 offsetWidth = width+border+padding,不包含margin offsetHei ...

  9. ios开发中,A valid provisioning profile for this executable was not found,的解决方法

    手头上的一个ios项目在上架后,再进行时出现了以上的这个错误,这是上架后忘了对一些配置进行复原 我的项目解决方法是: 是上面的这一块出现了问题,图片上的配置是正常的情况,但是上架的时候对其进行了修改, ...

  10. Android Viewpager PagerAdapter update data 刷新界面数据

    最近做的项目涉及到ViewPager数据刷新,网上的资料挺多,但是和现在做的这个不太相同,所以并没有找到有效的. 折腾了大半天,整理一下思路: 问题1: 后台刷新数据次数过多后,界面出现卡顿现象,判断 ...