Question:
On a straight street, there is a restaurant at location X.
Now there are n customers in the street ordering meals at the same time, each customer has an unhappy value increase speed.
V is added every minute before it reaches.
Now we need to minimize the unhappy value of all customers.
Train of Thought Analysis:
The first thought should be greedy. Send one side to the other.
However, if there is a dot on each side, the distance from the restaurant is very large. However, the distance between others is small. At this time, the optimal solution is to finish the small ones on both sides first.
So
DP [I] [J] [0] indicates that the [I-j] has been sent, and the minimum global dissatisfaction value of the person staying at the I position is displayed.
DP [I] [J] [1] indicates --------------------------- J position -----------------------------.
Each status can be transferred through four statuses.
That is, DP [I + 1] [J] [0] DP [I + 1] [J] [1] DP [I] [J-1] [0], DP [I] [J-1] [1]...
Then, deduce the added annoyance value.
# Include <cstdio> # include <iostream> # include <cstring> # include <algorithm> using namespace STD; struct node {int X, B; bool operator <(const node & CMP) const {return x <CMP. X ;}} P [1005]; int DP [1005] [1005] [2]; int sum [1005]; int query (int l, int R) {If (L> r) return 0; return sum [R]-sum [L-1];} int main () {int N, V, X; while (scanf ("% d", & N, & V, & X )! = EOF) {for (INT I = 1; I <= N; I ++) scanf ("% d", & P [I]. x, & P [I]. b); P [n + 1]. X = x, P [n + 1]. B = 0; sort (p + 1, P + 2 + n); memset (DP, 0x3f, sizeof DP); sum [0] = 0; for (INT I = 1; I <= n + 1; I ++) sum [I] = sum [I-1] + P [I]. b; int res; For (INT I = 1; I <= n + 1; I ++) {If (P [I]. X = x) {res = I; break;} DP [res] [res] [0] = DP [res] [res] [1] = 0; for (INT I = res; I> = 1; I --) {for (Int J = res; j <= n + 1; j ++) {if (I = J) continue; int rest = query (1, I) + query (J + 1, n + 1 ); DP [I] [J] [0] = min (DP [I] [J] [0], min (DP [I + 1] [J] [0] + (P [I + 1]. x-P [I]. x) * rest, DP [I + 1] [J] [1] + (P [J]. x-P [I]. x) * rest); DP [I] [J] [1] = min (DP [I] [J] [1], min (DP [I + 1] [J] [0] + (P [J]. x-P [I]. x) * (rest-P [I]. b) + (P [I + 1]. x-P [I]. x) * rest, DP [I + 1] [J] [1] + rest * (p [J]. x-P [I]. x) + (rest-P [I]. b) * (p [J]. x-P [I]. x); rest = query (1, I-1) + query (J, n + 1 ); DP [I] [J] [0] = min (DP [I] [J] [0], min (DP [I] [J-1] [0] + rest * (p [J]. x-P [I]. x) + (rest-P [J]. b) * (p [J]. x-P [I]. x), DP [I] [J-1] [1] + rest * (p [J]. x-P [J-1]. x) + (rest-P [J]. b) * (p [J]. x-P [I]. x); DP [I] [J] [1] = min (DP [I] [J] [1], min (DP [I] [J-1] [0] + rest * (p [J]. x-P [I]. x), DP [I] [J-1] [1] + (P [J]. x-P [J-1]. x) * rest);} printf ("% d \ n", V * min (DP [1] [n + 1] [0], DP [1] [n + 1] [1]);} return 0 ;}