HDU (1069)--monkey and Banana (LIS variant)

Source: Internet
Author: User

Test instructions

Now give you n a stone, then it is represented by coordinates (x, y, z). But it can have different methods, that is to say, its three coordinates can be rotated.

There is no limit to the number of stones, but each time it is necessary to keep the length and width of the bottom strictly decreasing, and then ask you what the maximum height you can spell with these stones.

Ideas:

Because there are a lot of coordinates, we can save every situation.

It is important to note that, at the time of saving, we have to keep X's coordinates greater than Y, so that we can sort them later.

Then it is just right to ask for the longest descending subsequence.

#include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include < set> #include <map> #include <math.h>using namespace std; #define MAXN 111#define inf 99999999int DP[MAXN]; struct Node{int x,y,z,s;} A[maxn];bool CMP (node A,node b) {if (a.x!=b.x) return A.x>b.x;else if (a.x==b.x) return a.y>b.y;} int main () {int N;int j=1;while (~scanf ("%d", &n)) {if (n==0) break;int t=0;for (int i=0;i<n;i++) {int x,y,z;scanf ("% d%d%d ", &x,&y,&z);a[t].x=x>y?x:y; a[t].y=x>y?y:x;a[t].z=z; t++;a[t].x=y>z?y:z; a[t].y=y>z?z:y; A[t].z=x; t++;a[t].x=x>z?x:z; a[t].y=x>z?z:x; a[t].z=y;t++;} Sort (a,a+t,cmp); memset (Dp,0,sizeof (DP));DP [0]=a[0].z;int ans=-1;for (int i=0;i<t;i++) {int res=0;for (int j=0;j <i;j++) {if (a[i].x<a[j].x&&a[i].y<a[j].y) | | | (a[i].x<a[j].y&&a[i].y<a[j].x)) {Res=max (res,dp[j]);}} Dp[i]=res+a[i].z;ans=max (Ans,dp[i]);} printf ("Case%d:maximum height =%d\n", J++,ans);}}

Although the topic is simple, but this problem is also from my own thought out of, from easy to difficult to practice down!

I believe that my own efforts, in the near future will certainly be able to taste the joy of AC puzzles!

@ All the people who study DP, come on!!!

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU (1069)--monkey and Banana (LIS variant)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.