Help jimmy--poj1661 (DP)

Source: Internet
Author: User

Title Link: http://poj.org/problem?id=1661

It's the same on the left, on the right:

#include <stdio.h>#include<string.h>#include<stdlib.h>#include<algorithm>using namespacestd;#defineN 1100#defineINF 0XFFFFFFstructnode{intL, R, H;} A[n];intCMP (node p, node Q) {returnP.H >Q.H;}intMain () {intT, n, x, Y, m,dp[n][2]; scanf ("%d", &T);  while(t--) {scanf ("%d %d%d%d", &n, &x, &y, &m);  for(intI=1; i<=n; i++) {scanf (" %d%d%d", &a[i]. L, &a[i]. R, &A[i].            H); dp[i][0] = dp[i][1] =INF; }        intans=INF; a[0]. L =x; a[0]. R =x; a[0]. H =y; Sort (A, a+n+1, CMP);///sort by height;A[n+1]. L =-22222; A[n+1]. R =22222; A[n+1]. H =0;///Ground;dp[0][0] = dp[0][1] =0;  for(intI=0; i<=n; i++)        {            intLl=1, rr=1;///ll and RR are used to mark the left and right sides of the plank from the block I have found the next foothold             for(intj=i+1; j<=n+1; J + +)            {                if( (! ll&&! RR) | | (A[i]. H-A[J]. H&GT;M))///you can jump out when you are not satisfied with the height or if you have the next landing point.                     Break; if(A[i]. L&GT;=A[J]. L && A[i]. L&LT;=A[J]. R && A[i]. H!=A[J]. H && LL)///When I fall from the left to the next platform J;{LL=0;///have found the landing point on the left;                    if(j==n+1)///If the landing point is the ground, you can take the minimum value;Ans=min (ans, dp[i][0]); Else///No side on ... Draw a picture, see clearly at one glance;{dp[j][0]=min (dp[j][0], dp[i][0]+ (A[i]. L-A[j].                        L)); dp[j][1]=min (dp[j][1], dp[i][0]+ (A[j]. RA[i].                    L)); }                }                if(A[i]. R&GT;=A[J]. L && A[j]. R>=a[i]. R && A[i]. H!=A[J]. H && RR)///the same as above;{RR=0; if(j==n+1) ans=min (ans, dp[i][1]); Else{dp[j][0]=min (dp[j][0], dp[i][1]+ (A[i]. RA[j].                        L)); dp[j][1]=min (dp[j][1], dp[i][1]+ (A[j]. RA[i].                    R)); } }}} printf ("%d\n", ans+y); }    return 0;}
View Code

Help jimmy--poj1661 (DP)

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.