Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/149.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 大小为4的严格递增序列的最大和_C++_Arrays_C_Algorithm_Dynamic Programming - Fatal编程技术网

C++ 大小为4的严格递增序列的最大和

C++ 大小为4的严格递增序列的最大和,c++,arrays,c,algorithm,dynamic-programming,C++,Arrays,C,Algorithm,Dynamic Programming,有没有更有效的方法来获得大小为4的严格递增子序列的最大和 我使用了DP,其中DP[I][j]=max(DP[k][j-1])这样k

有没有更有效的方法来获得大小为4的严格递增子序列的最大和

我使用了DP,其中
DP[I][j]=max(DP[k][j-1])
这样
k
A[k]
A
就是数组。 此解决方案的时间复杂度为n^2

我想降低时间复杂度

让数组为1,10,6,8,9,11,9,9,13
然后答案是13+11+9+8,对于每个
i
,从1到4,通过最大值和总和的降序来保持,这是您已经找到的最佳选项。(您可以使用skiplist、二叉树或其他任何方法)这将严格按照最大值和总和递减

然后,您的更新逻辑如下所示:

for i in [1, 2, 3, 4]:
    for j in your array:
        find for i-1 the best candidate whose max is < j:
        if found:
            create new candidate by adding j to that one
            look for best candidate of size i with max smaller than or equal to this
            if not found or its sum is < this one:
                insert new candidate into data structure
                delete from data structure any existing elements whose max >= this and whose sum is <= this.
[1,2,3,4]中的i的

对于数组中的j:
为i-1找到最大值小于j的最佳候选:
如果发现:
通过向该候选对象添加j来创建新候选对象
寻找尺寸为i且最大值小于或等于此值的最佳候选者
如果未找到或其总和小于此值:
在数据结构中插入新候选项

从数据结构中删除其max>=this且其总和为的任何现有元素,因为我无法理解该方法。请详细说明。这里的最大值是什么?@DwaipayanBarman最大值是升序的最大值。总和是升序的总和。关键的洞察是,如果在任何一点上有两个序列,其中A的最大值>=B,和一个和,那么整个点就是“丢弃不能尽快达到最优的序列,保留那些可能导致在易于搜索的排序数据结构中达到最优的序列”。谢谢,现在就知道了。