HDU1069 最长上升子序列

emm。。。。矩形嵌套 还记得吗。。。。就是它。。。

直接贴代码了。。。。

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main{
    final static int maxn = 1000000;
    final static int INF = 0xfffffff;
    public static class node{
        int x,y,h;
        node(int x,int y,int h)
        {
            this.x = x;
            this.y = y;
            this.h = h;
        }
    }
    public static void main(String[] args)  {
        Scanner cin = new Scanner(System.in);
        int cnt = 0;
        while(cin.hasNext())
        {
            ArrayList<node> Node = new ArrayList<>();
            int[] list = new int[maxn];
            int n = cin.nextInt();
            if(n == 0)
                break;
            for(int i=0;i<n;i++)
            {
                list[0] = cin.nextInt();
                list[1] = cin.nextInt();
                list[2] = cin.nextInt();
                Arrays.sort(list,0,3);
                Node.add(new node(list[0],list[1],list[2]));
                Node.add(new node(list[0],list[2],list[1]));
                Node.add(new node(list[1],list[2],list[0]));
            }
            Collections.sort(Node,new Comparator<node>() {
                public int compare(node a,node b)
                {
                    return a.x -b.x;
                }

            });
            int maxx = -INF;
            int[] dp = new int[maxn];
            for(int i=0;i<Node.size();i++)
            {
                dp[i] = Node.get(i).h;
                for(int j=0;j<i;j++)
                {
                    if(Node.get(i).x > Node.get(j).x && Node.get(i).y > Node.get(j).y && dp[j]+Node.get(i).h > dp[i])
                        dp[i] = dp[j] + Node.get(i).h;
                }
                maxx = Math.max(maxx, dp[i]);
            }
            System.out.println("Case " + ++cnt + ": maximum height = " + maxx);

        }

    }
}

原文地址:https://www.cnblogs.com/WTSRUVF/p/9063517.html

时间: 2024-12-20 12:37:36

HDU1069 最长上升子序列的相关文章

HDU1069:Monkey and Banana(最长上升子序列的应用)

题目:http://acm.hdu.edu.cn/showproblem.php?pid=1069 这题挺简单的,给定一个箱子的长宽高,要求啰箱子,但必须保证下面箱子的长和宽必须大于上面的箱子. 一个箱子,有六种情况,排序后,按照最长上升子序列来求解就行了. 代码如下: #include <iostream> #include <stdio.h> #include <string.h> #include <math.h> #include <algor

14-高效求最长公共子序列(二维数组存不下)

/*                                   See LCS again时间限制:1000 ms  |  内存限制:65535 KB难度:3 描述 There are A, B two sequences, the number of elements in the sequence is n.m; Each element in the sequence are different and less than 100000. Calculate the length

POJ 2533 - Longest Ordered Subsequence(最长上升子序列) 题解

此文为博主原创题解,转载时请通知博主,并把原文链接放在正文醒目位置. 题目链接:http://poj.org/problem?id=2533 Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence (a1, a2, ..., aN) be any sequence (ai1, ai2, ..., aiK)

最长公共子序列的代码实现

关于最长公共子序列(LCS)的相关知识,http://blog.csdn.net/liufeng_king/article/details/8500084 这篇文章讲的比较好,在此暂时不再详说. 以下是我代码实现两种方式:递归+递推: 1 #include <bits/stdc++.h> 2 using namespace std; 3 int A[100]; 4 int B[100]; 5 6 //int B[]={2,3,5,6,9,8,4}; 7 int d[100][100]={0};

HDU 3998 Sequence (最长递增子序列+最大流SAP,拆点法)经典

Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1666    Accepted Submission(s): 614 Problem Description There is a sequence X (i.e. x[1], x[2], ..., x[n]). We define increasing subsequ

算法面试题 之 最长递增子序列 LIS

找出最长递增序列 O(NlogN)(不一定连续!) 参考 http://www.felix021.com/blog/read.php?1587%E5%8F%AF%E6%98%AF%E8%BF%9E%E6%95%B0%E7%BB%84%E9%83%BD%E6%B2%A1%E7%BB%99%E5%87%BA%E6%9D%A5 我就是理解了一下他的分析 用更通俗易懂的话来说说题目是这样 d[1..9] = 2 1 5 3 6 4 8 9 7 要求找到最长的递增子序列首先用一个数组b[] 依次的将d里面

NYOJ 36 &amp;&amp;HDU 1159 最长公共子序列(经典)

链接:click here 题意:tip:最长公共子序列也称作最长公共子串(不要求连续),英文缩写为LCS(Longest Common Subsequence).其定义是,一个序列 S ,如果分别是两个或多个已知序列的子序列,且是所有符合此条件序列中最长的,则 S 称为已知序列的最长公共子序列. 输入 第一行给出一个整数N(0<N<100)表示待测数据组数 接下来每组数据两行,分别为待测的两组字符串.每个字符串长度不大于1000. 输出 每组测试数据输出一个整数,表示最长公共子序列长度.每组

poj1159 Palindrome(最长公共子序列)

Palindrome Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 52966   Accepted: 18271 Description A palindrome is a symmetrical string, that is, a string read identically from left to right as well as from right to left. You are to write a

动态规划(4)——最长上升子序列(作业题NYOJ201)

作业题 描述 小白同学这学期有一门课程叫做<数值计算方法>,这是一门有效使用数字计算机求数学问题近似解的方法与过程,以及由相关理论构成的学科-- 今天他们的Teacher S,给他们出了一道作业题.Teacher S给了他们很多的点,让他们利用拉格朗日插值公式,计算出某严格单调函数的曲线.现在小白抄下了这些点,但是问题出现了,由于我们的小白同学上课时走了一下神,他多抄下来很多点,也就是说这些点整体连线不一定还是严格递增或递减的了.这可怎么处理呢.为此我们的小白同学制定了以下的取点规则: 1.取