Main topic:
There are n individuals, living in a straight line. I personal coordinates is XI, the street has a takeaway restaurant location is X, now the restaurant staff to give everyone on the street food, sent back to the restaurant, the speed of delivery is V, everyone has an unsatisfactory value, when the person delivered a meal a minute every night, then this person's dissatisfaction value increases bi. The total unsatisfied value is required to be minimal. ===============================================================================================================
#include <cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<cmath>using namespaceStd;typedefLong LongLL;ConstLL INF = 1e9+7;ConstLL MAXN = 1e3+5;ConstLL MOD = 1e9+7;intdp[2][MAXN][MAXN], SUM[MAXN];structnode{intX, B; BOOLFriendoperator<(node A, node B) {returnA.x <b.x; }} P[MAXN];intMain () {intN, v, x; while(CIN >> N >> v >>x) { for(intI=1; i<=n; i++) Cin>> P[i]. X >>P[i]. B P[n+1]. x = x, p[n+1]. B =0; N++; Memset (DP,0,sizeof(DP)); memset (SUM,0,sizeof(sum)); Sort (P+1, p+1+N); sum[0] =0; for(intI=1; i<=n; i++) Sum[i]= sum[i-1] +P[i]. B intStar; for(intI=0; i<=n+1; i++) for(intj=0; j<=n+1; J + +) dp[0][I][J] = dp[1][I][J] =INF; for(intI=1; i<=n; i++) { if(P[i]. X = =x) {Star=i; Break; }} dp[0][star][star] = dp[1][star][star] =0; for(intI=star; i>=1; i--) for(intJ=star; j<=n; J + +) {dp[0][i][j] = min (dp[0][I][J], dp[0][i+1][J] + (p[i+1]. X-p[i]. X) * (sum[n]-sum[j]+sum[i])); dp[0][i][j] = min (dp[0][I][J], dp[1][i+1][J] + (P[j]. X-p[i]. X) * (sum[n]-sum[j]+Sum[i])) ; dp[1][i][j] = min (dp[1][I][J], dp[0][i][j-1] + (P[j]. X-p[i]. X) * (sum[n]-sum[j-1]+sum[i-1]) ); dp[1][i][j] = min (dp[1][I][J], dp[1][i][j-1] + (P[j]. x-p[j-1]. X) * (Sum[n]-sum[j-1] + sum[i-1]) ); } printf ("%d\n", Min (dp[0][1][n],dp[1][1][n]) *v); } return 0;}
ZOJ 3469Food Delivery