HDU 1069 Monkey and Banana

Source: Internet
Author: User

Feel pure DP problem basically is to give some number or object, ask for a maximum value what

This problem on the first layer and the next layer of the placement of a limited relationship, so to add a marker, mark the original top layer is which, and then DP

A block of unlimited supply, that is, the equivalent of each block, in fact, are three kinds of blocks, and according to the topic requires that each block can only be put a piece

Sort the coordinates by X

DP[I][J] represents the maximum height of the stacking layer I, at the top of the first J-type block

Then Dp[i][j]=max (dp[i][j],dp[i-1][0, 1, 2....l]+z[j])

And then add a judging condition.

if ((r[k].x>r[j].x&&r[k].y>r[j].y) | | | (R[K].Y>R[J].X&&R[K].X>R[J].Y))
It was just beginning to write
if (R[K].X>R[J].X&&R[K].Y>R[J].Y)
Always in WA

#include <stdio.h> #include <algorithm> #include <string.h>using namespace Std;const int inf=1< <30; #define N 105struct rec{int x, Y, Z;} R[n];int CMP (Rec A,rec b) {if (a.x==b.x) return A.y>b.y;return a.x>b.x;} int Dp[n][n];//dp[i][j]: The maximum height of the first layer of block J when the block is placed on top of void Init () {memset (dp,0,sizeof (DP));} int main () {#ifndef online_judgefreopen ("In.txt", "R", stdin), #endifint n,cas=1;while (scanf ("%d", &n), n) {init (); int l=1,xx,yy,zz;for (int i=0;i<n;i++) {scanf ("%d%d%d", &xx,&yy,&zz); r[l].x=xx;r[l].y=yy;r[l++].z=zz ;//r[l].x=xx;r[l].y=zz;r[l++].z=yy;r[l].x=yy;r[l].y=zz;r[l++].z=xx;//r[l].x=yy;r[l].y=xx;r[l++].z=zz;r[l].x=zz ; r[l].y=xx;r[l++].z=yy;//r[l].x=zz;r[l].y=yy;r[l++].z=xx;} R[0].x=inf;r[0].y=inf;r[0].z=inf;sort (r+1,r+l,cmp); for (int i=1;i<l;i++) {//i is the layer of the tower for (int j=i;j<l;j++) {//j <i is meaningless because J has a maximum number of j-1, and I represents the layer for (int k=0;k<l;k++) {if (R[K].X&GT;R[J].X&AMP;&AMP;R[K].Y&GT;R[J].Y) | | (R[K].Y&GT;R[J].X&AMP;&AMP;R[K].X&GT;R[J].Y)) Dp[i][j]=max (Dp[i][j],dp[i-1][k]+R[J].Z);} }}int ans=0;for (int i=1;i<l;i++) {for (int j=i;j<l;j++) {Ans=max (ans,dp[i][j]);}} printf ("Case%d:maximum height =%d\n", Cas++,ans);}}


HDU 1069 Monkey and Banana

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.