Topic Links:
Zoj 3469 Food Delivery
Title Description:
On the x-axis, there are n guests ordered to take out, each customer because of the update progress of different, so in the time of the external purchase of the increase in the value of anger per second different. The location of the guests and the restaurant, as well as the increased anger per minute, and the time required for a one-kilometer walk of the express brother. Ask for the minimum rage value of n guests after delivery of the takeaway?
Problem Solving Ideas:
Interval DP, a freshman time to do provincial practice when you see this type of topic, but today, because of the age, or GG.
Add the spot where the restaurant is located, and then sort by the position on the x-axis. Starting from the location of the restaurant to the left and right Dp,dp[x][y][z] represents the minimum cost of processing the interval [y, z] to stay in the x direction, and this topic is to preprocess the cost of not adding points. Then select the optimal.
1#include <cmath>2#include <cstdio>3#include <cstring>4#include <iostream>5#include <algorithm>6 using namespacestd;7typedefLong LongLL;8 Const intINF =0x3f3f3f3f;9 Const intMAXN =1010;Ten structnode One { A intx, B; - } P[MAXN]; -LL dp[2][MAXN][MAXN], SUM[MAXN];//Dp[0][x][y] Left interval [x, y], dp[1][x][y] right interval [x, y] the - BOOLCMP (Node A, Node B) - { - returnA.x <b.x; + } - + intMain () A { at intN, v, x; - while(SCANF (" %d%d%d", &n, &v, &x)! =EOF) - { - for(intI=1; i<=n; i++) -scanf ("%d%d", &p[i].x, &p[i].b); -p[++n].x =x; inP[N].B =0; -Sort (p+1, p+n+1, CMP); to + for(intI=0; i<=n; i++) - for(intj=0; j<=n; J + +) thedp[0][I][J] = dp[1][I][J] =INF; * intTEM =0; $ for(intI=1; i<=n; i++)Panax Notoginseng if(p[i].x = =x) - { theTEM =i; + Break; A } thedp[0][tem][tem] = dp[1][tem][tem] =0; + -sum[0] =0; $ for(intI=1; i<=n; i++) $Sum[i] = sum[i-1] +p[i].b; - - the for(intI=tem; I>0; i--) - for(intJ=tem; j<=n; J + +)Wuyi { the if(i = = j)Continue; -dp[0][i][j] = min (dp[0][I][J], dp[0][i+1][j]+ (Sum[n]-sum[j]+sum[i]) * (p[i+1].x-p[i].x)); Wudp[0][i][j] = min (dp[0][I][J], dp[1][i+1][j]+ (Sum[n]-sum[j]+sum[i]) * (p[j].x-p[i].x)); - Aboutdp[1][i][j] = min (dp[1][I][J], dp[1][i][j-1]+ (sum[n]-sum[j-1]+sum[i-1]) * (p[j].x-p[j-1].x)); $dp[1][i][j] = min (dp[1][I][J], dp[0][i][j-1]+ (sum[n]-sum[j-1]+sum[i-1]) * (p[j].x-p[i].x)); - } -printf ("%lld\n", v * min (dp[0][1][n], dp[1][1][n])); - } A return 0; +}
Zoj 3469 Food Delivery (interval dp)