编程介的小学生 2019-03-17 16:08 采纳率: 20.5%
浏览 330

子集序列的最大连续值问题的算法,如何利用C语言的方式编程来实现

Problem Description
I konw you guys have solve so many problems about increasing sequence, this time, a little change has been made.
Assume that there is a sequence S = {s1, s2, s3, ..., sn}, si = (xi, yi).You should find two increasing subsequence L1 and L2, and they have no common elements, means L1∩L2 = φ, and the sum of their lenth is as max as possible.
Here we assume si > sj is that (xi > xj && yi > yj) or (xi >= xj && yi > yj) or (xi > xj && yi >= yj). I will ensure that all elements' coordinates are distinct, i.e., si != sj (i!=j).

Input
The input consists of multiple test cases. Each case begins with a line containing a positive integer n that is the length of the sequence S, the next n lines each contains a pair integers (xi, yi), i = 1,...n.1 <= n <= 5000,1<=xi,yi<=2^31.

Output
For each test case, output one line containing the the maximum sum of the two increasing subsequence L1 and L2 you can find.

Sample Input
3
1 3
3 1
2 2
4
1 2
2 1
4 3
3 4

Sample Output
2
4

  • 写回答

1条回答 默认 最新

  • 松子配玉米 2019-03-18 13:26
    关注

    问题描述
    我知道你们已经解决了许多关于增加序列的问题,这一次,已经做了一点改变。
    假设有一个序列S = {s1,s2,s3,...,sn},si =(xi,yi)。你应该找到两个增加的子序列L1和L2,它们没有共同的元素,意味着L1∩ L2 =φ,并且它们的长度之和尽可能地最大。
    这里我们假设si> sj是(xi> xj && yi> yj)或(xi> = xj && yi> yj)或(xi> xj && yi> = yj)。 我将确保所有元素的坐标是不同的,即si!= sj(i!= j)。
    输入
    输入包含多个测试用例。 每个案例都以包含正整数n的行开始,该正整数n是序列S的长度,接下来的n行每行包含一对整数(xi,yi),i = 1,... n.1 <= n <=5000,1<= XI,易<=2 ^ 31。
    输出
    对于每个测试用例,输出一行,其中包含您可以找到的两个递增子序列L1和L2的最大总和。
    Sample Input
    3
    1 3
    3 1
    2 2
    4
    1 2
    2 1
    4 3
    3 4
    Sample Output
    2
    4

    为了回答问题,先把您的问题机翻了一遍,不是很懂您想问什么。但关于子集序列的最大连续值问题的算法,我还是有一些想法的。
    给您举个栗子:
    如给定序列{ -2, 11, -4, 13, -5, -2 },其最大连续子序列为{11,-4,13},最大连续子序列和即为20。
    那么我们可以直接入手代码,求出所有可能连续子列的和即可:

    int MaxSubSequm1(int A[], int N)
    {
    int oneSum, maxSum = 0;
    int i, j, k;
    for (i = 0; i < N; i++) {

    for (j = i; j < N; j++){
    oneSum = 0;

    for (k = i; k <= j; k++)

    oneSum += A[k];

    if (oneSum>maxSum)

    maxSum = oneSum;

        }
    
    }
    return maxSum;   
    

    }

    我只能做到一种方法,这边有一位博主的详尽解答,希望对您有所帮助。
    https://blog.csdn.net/zxc123e/article/details/79679488

    评论

报告相同问题?

悬赏问题

  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集