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>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>=A[J]. L && A[i]. L<=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>=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)