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. shorter concat [reverse longer]

    shorter concat [reverse longer] Description: Given 2 strings, a and b, return a string of the form:  ...

  2. 使用SAE部署Flask,使用非SAE flask版本和第三方依赖包的方法

    目前SAE的Flask的版本为0.7,但是我从学习开始的flask版本就已经是0.10了,而且一些扩展都是使用的0.10以后的from flask.ext.特性进行引入的.所以需要修改SAE的环境. ...

  3. jekyll themes

    jekyll主题下载: https://mademistakes.com/work/jekyll-themes/ https://github.com/jekyll/jekyll/wiki/Theme ...

  4. poj 2109 Power of Cryptography (double 精度)

    题目:http://poj.org/problem?id=2109 题意:求一个整数k,使得k满足kn=p. 思路:exp()用来计算以e为底的x次方值,即ex值,然后将结果返回.log是自然对数,就 ...

  5. acdream 瑶瑶带你玩激光坦克 (模拟)

    瑶瑶带你玩激光坦克 Time Limit: 2000/1000MS (Java/Others)    Memory Limit: 256000/128000KB (Java/Others) Submi ...

  6. MYSQL使用二进制日志来恢复数据

    mysqlbinlog工具的使用,大家可以看MySQL的帮助手册.里面有详细的用, 在这个例子中,重点是--start-position参数和--stop-position参数的使用. ·--star ...

  7. Project Euler 26 Reciprocal cycles

    题意:求1到n中所有数的倒数中循环小数循环体最长的数 解法:如果一个数的质因子只有2和5,那么这个数的倒数一定不是一个循环小数.如果一个数含有质因子2或5,那么它的循环体和去掉质因子2和5之后的数的循 ...

  8. 【原】Storm 守护线程容错机制

    Storm入门教程 1. Storm基础 Storm Storm主要特点 Storm基本概念 Storm调度器 Storm配置 Guaranteeing Message Processing(消息处理 ...

  9. ubuntu安装和卸载软件命令

    ubuntu安装和卸载软件命令 Ubuntu软件安装与删除相关命令 安装软件 命令: apt-get install softname1 softname2 softname3…… 卸载软件 命令: ...

  10. C# 调用Dll 传递字符串指针参(转)

    http://www.cnblogs.com/jxsoft/archive/2011/07/06/2099061.html