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

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

Sample Input

  1. 4 3
    3 1 4 2

Sample Output

  1. 5

HINT

题意

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

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

题解:

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

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

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

代码:

  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<queue>
  4. #include<map>
  5. #include<algorithm>
  6. #include<string.h>
  7. using namespace std;
  8.  
  9. #define maxn 3225020
  10.  
  11. int a[maxn];
  12. int dp1[maxn];
  13. int dp2[maxn];
  14. int dp3[maxn];
  15. int lis[maxn];
  16.  
  17. int main()
  18. {
  19. int n,t;scanf("%d%d",&n,&t);
  20. for(int i=;i<=n;i++)
  21. scanf("%d",&a[i]);
  22. if(t<=)
  23. {
  24. int ans = ;
  25. for(int i=;i<=n;i++)
  26. for(int j=;j<t;j++)
  27. a[j*n+i] = a[i];
  28. for(int i=;i<=n*t;i++)
  29. {
  30. lis[i]=;
  31. for(int j=;j<i;j++)
  32. if(a[i]>=a[j])
  33. lis[i]=max(lis[i],lis[j]+);
  34. ans = max(lis[i],ans);
  35. }
  36. printf("%d\n",ans);
  37. return ;
  38. }
  39. int k = ;
  40. for(int i=;i<=n;i++)
  41. dp2[a[i]]++;
  42. for(int i=;i<=n;i++)
  43. for(int j=;j<=k;j++)
  44. a[j*n+i] = a[i];
  45.  
  46. for(int i=;i<=k*n;i++)
  47. {
  48. lis[i]=;
  49. for(int j=;j<i;j++)
  50. if(a[i]>=a[j])
  51. lis[i]=max(lis[i],lis[j]+);
  52. dp1[a[i]] = max(dp1[a[i]],lis[i]);
  53. }
  54.  
  55. memset(lis,,sizeof(lis));
  56.  
  57. reverse(a+,a++k*n);
  58. for(int i=;i<=k*n;i++)
  59. {
  60. lis[i]=;
  61. for(int j=;j<i;j++)
  62. if(a[i]<=a[j])
  63. lis[i]=max(lis[i],lis[j]+);
  64. dp3[a[i]] = max(dp3[a[i]],lis[i]);
  65. }
  66.  
  67. int ans = ;
  68. for(int i=;i<=;i++)
  69. for(int j=i;j<=;j++)
  70. for(int m=j;m<=;m++)
  71. ans = max(dp1[i]+dp2[j]*(t-*k)+dp3[m],ans);
  72. printf("%d\n",ans);
  73. }

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. freemarker截取字符串

    [#if   a.title?length   lt   23   ]   ${a.title} [#else]${a.title[0..22]}...[/#if]

  2. 错误代码: 1005 Can't create table 'hibernate.bill' (errno: 150)

    主要问题以及解决办法是: 1,MySQL支持外键约束,并提供与其它DB相同的功能,但表(外键表和外键主表)类型必须为 InnoDB,外键表和外键主表的类型都要是innoDB 建表约束语句: user表 ...

  3. bzoj1385: [Baltic2000]Division expression

    欧几里得算法.可以发现规律,a[2]作为分母,其他作为分子,必定是最好的选择.判断是否为整数即可. #include<cstdio> #include<cstring> #in ...

  4. acdream 小晴天老师系列——晴天的后花园 (暴力+剪枝)

    小晴天老师系列——晴天的后花园 Time Limit: 10000/5000MS (Java/Others)    Memory Limit: 128000/64000KB (Java/Others) ...

  5. android数据库(随apk一起发布数据库)

    读取数据库+数据库版本更新 注意: a, 将随apk发布的数据库放在android工程下/res/raw路径下. b, 数据库文件存到手机上时,路径在/data/data/你的包名/databases ...

  6. SSH proxy

    # for Linux ssh nobody@guoliangwu.com -P 22 -C -N -D 127.0.0.1:6500 # for windows(PuTTY) plink nobod ...

  7. 计算N的阶层

    int factorial(int n) { int i, result; ; i <= n; i++) result *= i; return result; } int factorial2 ...

  8. NOIP2009 靶形数独

    4.靶形数独 (sudoku.pas/c/cpp) [问题描述] 小城和小华都是热爱数学的好学生, 近,他们不约而同地迷上了数独游戏,好胜的他们想用数独来一比高低.但普通的数独对他们来说都过于简单了, ...

  9. 4.1Reduction模型

    1. Reduction Reduction是一种广泛使用的计算模型,特别是在并行计算领域.简单地来说,Reduction就是一系列的划分(Partition)和汇总(Summarize)操作的集合: ...

  10. 【poj2891】Strange Way to Express Integers

    题意: 给出n个模方程x=a(mod r) 求x的最小解 题解: 这就是个线性模方程组的模版题- - 但是有一些要注意的地方 extgcd算出来的解x可能负数  要让x=(x%mo+mo)%mo 而且 ...