BestCoder Round #13 1003(单调性DP)HDU5064

Find Sequence

Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)

Total Submission(s): 68    Accepted Submission(s): 12

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

题意:RT

思路:首先排序是肯定的,然后无论怎么选条件1始终满足

现在看条件2,因为条件2还跟前后的差值有关

那么就要考虑DP了

用DP[i][j]表示以第i和第j个数结尾的最长子序列

那么转移方程为DP[i][j]=max(DP[k][i]) + 1,其中j>i ,i>=k

这样暴力算是n^3的复杂度,显然会超时

注意这是有个单调性的,DP[i][j]满足的最优值一定DP[i][j+1]也可以取,所以在j增大的时候,k不必重新从i开始递减(因为这段重复的区间之前已经算过了)

k只需要继续以前的位置递减即可,保存最优值,然后赋给dp[i][j]

时间: 2024-08-06 16:00:27

BestCoder Round #13 1003(单调性DP)HDU5064的相关文章

从lca到树链剖分 bestcoder round#45 1003

bestcoder round#45 1003 题,给定两个点,要我们求这两个点的树上路径所经过的点的权值是否出现过奇数次.如果是一般人,那么就是用lca求树上路径,然后判断是否出现过奇数次(用异或),高手就不这么做了,直接树链剖分.为什么不能用lca,因为如果有树退化成链,那么每次询问的复杂度是O(n), 那么q次询问的时间复杂度是O(qn) 什么是树链剖分呢? 就是把树的边分成轻链和重链 http://blogsina.com.cn/s/blog_6974c8b20100zc61.htmlh

BestCoder Round #29 1003 (hdu 5172) GTY&#39;s gay friends [线段树 判不同 预处理 好题]

传送门 GTY's gay friends Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 264    Accepted Submission(s): 57 Problem Description GTY has n gay friends. To manage them conveniently, every morning he o

HDU 5806 NanoApe Loves Sequence Ⅱ(尺取+思维)——BestCoder Round #86 1003

传送门 NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/131072 K (Java/Others)Total Submission(s): 514    Accepted Submission(s): 248 Problem Description NanoApe, the Retired Dog, has returned back to prepare for f

HDU 5778 abs(暴力枚举)——BestCoder Round #85 1003

传送门 abs Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1474    Accepted Submission(s): 511 Problem Description Given a number x, ask positive integer y≥2, that satisfy the following condition

BestCoder Round #87 1003 LCIS[序列DP]

LCIS Accepts: 109 Submissions: 775 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) 问题描述 Alex有两个序列a1a2...ana?1??,a?2??,...,a?n??和b1b2...bmb?1??,b?2??,...,b?m??. 他想找到它们的最长公共递增子序列, 并且这个子序列的值是连续的(xx1...y1yx,x+1,...,y−1,y)

HDU 5682/BestCoder Round #83 1003 zxa and leaf 二分+树

zxa and leaf Problem Description zxa have an unrooted tree with n nodes, including (n−1) undirected edges, whose nodes are numbered from 1 to n. The degree of each node is defined as the number of the edges connected to it, and each node whose degree

BestCoder Round#8 1003

dp[i][j] 表示以i结尾的长度为j的递增子序列dp[i][j] = sum(dp[k][j])     k<i && a[i] >a[j]如果只是单纯的循环for(j=2; j<=m; ++j) for(i=1; i<=n; ++i) for(k=1; k<i; ++k) if(a[i] > a[j]) dp[i][j] += dp[k][j-1];时间复杂度是O(n * n * m)   TLE但是k循环可以用树状数组来优化,k循环可以看做是一个

BestCoder Round #47 1003

solution : 就按题解敲了一遍,好久没写这种dp 1 #include <cstdio> 2 #include <cstring> 3 #include <string> 4 #include <vector> 5 #include <algorithm> 6 #include <iostream> 7 using namespace std; 8 typedef long long LL; 9 const int MAX =

HDU5807 Keep In Touch (BestCoder Round #86 D ) 分布式dp

#include <cstdio> #include <cstring> #include <cmath> #include <vector> #include <algorithm> using namespace std; typedef long long LL; const int N = 50+2; const int mod = 998244353; int T,n,m,lim,q,tot,w[N],dp[N][N][N][3],he