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. .NET中各种不同的Timer之间区别

    System.Timer.Timer 根据命名空间看这个类貌似才是标准的Timer,它提供Interval属性和Elapsed事件.可以每隔一个时间周期触发一次Elapsed事件.在ThreadPoo ...

  2. 剑指Offer:从第一个字符串中删除第二个字符串中出现过的所有字符

    // 从第一个字符串中删除第二个字符串中出现过的所有字符 #include <stdio.h> char* remove_second_from_first( char *first, c ...

  3. 安装ejabberd2并配置MySQL为其数据库

    以前用过openfire做为服务器,但是openfire的集群支持不是很好,所以改用Ejabberd,由于它是用Erlang语言开发的,其并发率与分布式的功能都是很强悍的,在此我记录一下我的安装与配置 ...

  4. Spring Bean之间的关系

    bean之间的关系:继承和依赖继承bean的配置 Spring允许继承bean的配置,被继承的bean称为父bean,继承这个父bean的bean称为子bean 子bean从父bean中继承配置,包括 ...

  5. ubuntu下eclipse打开win下的代码中文出现乱码

    问题出现的原因:因为windows下默认的编码是GBK,在ubuntu下是UTF-8所以,所以在windows下的注释,在ubuntu下就变成了乱码. 解决的方案: 1)  eclipse->w ...

  6. 浅析WCF与WebService、WPF与Silverlight 区别

    由于在<Windows服务调用Quartz.net 实现消息调度>中,涉及到ASP.NET Web Service //WebServiceSoapClient client = new ...

  7. How to cancel parallel loops in .NET C# z

    Cancellation token Parallel options CancellationTokenSource cancellationTokenSource = new Cancellati ...

  8. 【原创】LoadRunner Java Vuser脚本的配置和调试指南

    1 编写目的 本文介绍了Loadrunner多负载压力机的配置,并通过测试Java Vuser的数据库连接脚本对配置结果进行了验证,同时对配置过程中遇到的问题和解决的过程进行了记录,关于Java数据库 ...

  9. 用COM方式快速导出到Excel一例,批量导出

    开发中用到填充Excel时,一个一个的填充不免太慢,现有用数组方式填充一例,可以实现COM方式快速填充. C#,VBA中用法类似 适用场景:需要自动化操作Excel的方式下使用,比较除填充数据外还要自 ...

  10. EventBus使用小记

    自从使用了EventBus,代码干净了好多. 从此你不用startActivityForResult了,从此你不用再写注册BroadcastReceiver了,从此你不用再写一些回调了. 只需要在需要 ...