Find Sequence

Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 279    Accepted Submission(s): 80

Problem Description
Give you an positive integer sequence a1,a2,…,ai,…,an, and they satisfy a1+a2+…+ai+…+an=M(0<M≤222).
We can find new sequence b1=aid1,b2=aid2,…,bx=aidx,…,by=aidy,…,bt=aidt, where if x != y then idx!=idy. and this sequence satisfy:
(1) b1≤b2≤…≤bt 
(2) b2−b1≤b3−b2≤⋯≤bt−bt−1
We can find many sequences b1,b2,b3,…,bt. But we only want to know maximum t.
Input
The first line in the input file is an Integer T(1≤T≤30).
The first line of each test case contains two integer n,M(0<M≤222).
Then a line have n integer, they represent a1,a2,…,ai,…,an.
Output
For each test case, output the maximum t.
Sample Input
2 6 19 3 2 1 3 4 6 1 4194304 4194304
Sample Output
5 1

Hint

For the first testcase, The Sequence is 1 2 3 4 6

Source
BestCoder Round #13
题意: 在一个数列里面取出一些数,满足一些条件
官方题解

首先考虑解的结构一定是C1,C1,…,C1,C2,C3,…,Cm这种形式,其中满足C1<C2<C3<…<Cm
所以对a1,a2,a3,…,an去重后从小到大排序得到c1,c2,c3,…,cx其中x是sqrt(M)级别的,用DP[i][j]表示以ci和cj结尾的满足条件的最长序列 首先初值化 DP[i][i]=count(ci) 即ci在原序列中的个数。 而dp[i][j]=max(dp[k][i] 其中k≤i还满足ci−ck≤cj−ci)+1 这样的复杂度是 O(x^3),在题中x最大为1000级别所以会超时,要使用下面优化 因为 dp[i][j]=max(dp[k][i] 其中k≤i还满足ci−ck≤cj−ci)+1 dp[i][j+1]=max(dp[k][i] 其中k≤i还满足ci−ck≤cj+1−ci)+1 注意到cj+1>cj 所以满足ci−ck≤cj−ci的dp[k][i]必然满足ci−ck≤cj+1−ci因而不必重复计算 即最后复杂度可以为O(x^2).

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<set>
#include<stack>
#include<map>
#include<ctime>
#include<bitset>
#define LL long long
#define maxn (1<<22)+10
using namespace std;int cnt[maxn],c[2010],dp[2010][2010];
int main()
{int i,n,m,j,k;int tmp,T,x,ans;cin >>T ;while(T--){scanf("%d%d",&n,&m) ;memset(cnt,0,sizeof(cnt));for( i = 1 ; i <= n ;i++){scanf("%d",&x) ;cnt[x]++;}n = 0 ;memset(dp,0,sizeof(dp));ans=0;for( i =0 ; i <= m ;i++)if(cnt[i]){c[++n]=i;dp[n][n]=cnt[i];ans=max(cnt[i],ans);}for( i = 1 ; i <= n ;i++){tmp=dp[i][i];k = i ;for( j = i+1 ; j <= n ;j++){for( ; k >= 1 ;k--){if(c[j]-c[i] >= c[i]-c[k])tmp = max(tmp,dp[k][i]+1) ;else break ;}dp[i][j]=tmp;ans=max(ans,dp[i][j]);}}printf("%d\n",ans);}return 0 ;
}

View Code

转载于:https://www.cnblogs.com/20120125llcai/p/4032336.html

hdu 5064 Find Sequence相关推荐

  1. HDU 1005 Number Sequence

    [题目]                                                   Number Sequence Time Limit: 2000/1000 MS (Jav ...

  2. HDU 5400 Arithmetic Sequence

    HDU 5400 Arithmetic Sequence /** HDU 5400 Arithmetic Sequence 直接预处理求解就好了 预处理找出以a[i]结尾最长的subArr长度(满足条 ...

  3. HDU.1005 Number Sequence

    原题 HDU.1005 Number Sequence 分类 杂题 题意 给定一个数列{an}\left\{ a_n \right\}{an​}的前两项a1a_1a1​.a2a_2a2​,以及其递推公 ...

  4. HDU 1560 DNA sequence(DNA序列)

    HDU 1560 DNA sequence(DNA序列) Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K  ...

  5. HDU 1711 Number Sequence(KMP算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1711 Number Sequence Time Limit: 10000/5000 MS (Java/ ...

  6. HDU 6304 Chiaki Sequence Revisited

    题目链接 : http://acm.hdu.edu.cn/showproblem.php?pid=6304 多校contest1 Problem Description Chiaki is inter ...

  7. hdu 2454 Degree Sequence of Graph G

    点击打开链接 Degree Sequence of Graph G Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/3276 ...

  8. HDU 5306 Gorgeous Sequence

    5306 ( Gorgeous Sequence ) 思路: 吉司机线段树 维护最大值和次大值,大于最大值不改,在最大值和次大值之间的直接修改,小于次大值递归修改. 代码: #pragma GCC o ...

  9. HDU 1711 -Number Sequence(KMP)

    题目 Number Sequence Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  10. hdu 1560 DNA sequence(迭代加深搜索)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1560 题意:从n个串中找出一个最短的公共串,,该公共串对于n个字符串不要求连续,即只要保持相对顺序就好 ...

最新文章

  1. Nature | 原核生物基因的生物地理学研究
  2. Maximum Product of Word Lengths
  3. BUUCTF crackMe
  4. Fail2ban初识
  5. AS3.0 对象键和内存管理
  6. linux下oracle 9204 soft only,linux 下oracle 9i的安装
  7. java file rename 失败_java重命名文件造成文件不可读写
  8. MySQL+Tomcat+JVM,看完还怕面试官
  9. php mysql 秒杀_redis+PHP实现高并发下秒杀数据入库的问题
  10. 如何检查数组是否有重复值
  11. PAT (Basic Level) Practice1001 害死人不偿命的(3n+1)猜想
  12. 论文笔记_S2D.66_ICRA_2021_LVI-SAM: 紧耦合的激光视觉惯导SLAM系统
  13. 阿里云祝顺民:未来的网络是云网一体,应用感知不到网络的存在
  14. python数据存储到access_Python操作Access数据库基本步骤分析
  15. 思科网络工程师面试题
  16. Statement和PreparedStatement的区别
  17. RHEL7安装配置FTP服务
  18. 华为LTC专家铁三角实战专家许浩明老师辅导长沙卷烟厂管理变革【华为案例分享】
  19. React实战之React+Redux实现一个天气预报小项目
  20. S7-1200使用集成库FB285控制G120变频器的基本步骤

热门文章

  1. 162天,从华为外包5k转岗正式员工15k,心酸只有自己知道
  2. 【算法】h0145. 会议安排(贪心算法)
  3. 伯努利试验及n重伯努利试验
  4. Python新书上市,强烈推荐!《Python网络数据爬取及分析从入门到精通(爬取篇)》导读
  5. 罗永浩写给俞敏洪的信
  6. 韩媒:开城韩商访朝申请或最晚25日出结果
  7. springboot基于微信小程序的在线考试系统
  8. 当企业网站跳出率超过70%,就要查找原因改进了
  9. python3中26个英文字母排序_26个英文字母的排序是怎样排的?
  10. Shader山下(十九)标记Tag