Zoj3469 food delivery interval DP

Source: Internet
Author: User

A fast food restaurant delivers food. Now N families make orders by phone.V-1But every family has an unhappy value, which doubles every minute. To a certain extent, the family will no longer order takeout, now, in order to have more family orders in the future, the sum of unhappy values of all users should be minimized when takeout is sent.

Train of Thought: interval DP

DP [I] [J] [0]: indicates the minimum value in the range from I to J and remains at the I point.

DP [I] [J] [1]: indicates the minimum value in the range from I to J and remains at the J point.

The transfer equation is

Sum [I] indicates the sum of 1 to I. When I to J is enumerated, the intervals (0, I) and (J, n) must be doubled.

DP [I] [J] [0] = min (DP [I] [J] [0], DP [I + 1] [J] [0] + (sum [I] + sum [N]-sum [J]) * (p [I + 1]. x-P [I]. x ));
DP [I] [J] [0] = min (DP [I] [J] [0], DP [I + 1] [J] [1] + (sum [I] + sum [N]-sum [J]) * (p [J]. x-P [I]. x ));

DP [I] [J] [1] = min (DP [I] [J] [1], DP [I] [J-1] [0] + (sum [I-1] + sum [N]-sum [J-1]) * (p [J]. x-P [I]. x ));
DP [I] [J] [1] = min (DP [I] [J] [1], DP [I] [J-1] [1] + (sum [I-1] + sum [N]-sum [J-1]) * (p [J]. x-P [J-1]. x ));

1 // # pragma comment (linker, "/Stack: 167772160") // manually expand the stack ~~~~ HDU uses C ++ to submit 2 # include <cstdio> 3 # include <cstring> 4 # include <cstdlib> 5 # include <iostream> 6 # include <queue> 7 # include <stack> 8 # include <cmath> 9 # include <set> 10 # include <algorithm> 11 # include <vector> 12 # include <map> 13 // # include <malloc. h> 14 using namespace STD; 15 # define CLC (a, B) memset (a, B, sizeof (a) 16 # define ll long long17 const int INF = 0x3f3f3f3f; 18 const double EPS = 1e-5; 19 // Const double Pi = ACOs (-1); 20 const ll mod = 9901; 21 const int n = 1010; 22 23 // inline int R () {24 // int x = 0, F = 1; char CH = getchar (); 25 // while (CH> '9' | ch <'0 ') {If (CH = '-') F =-1; CH = getchar ();} 26 // while (CH> = '0' & Ch <= '9') {x = x * 10 + CH-'0'; CH = getchar ();} 27 // return x * F; 28 //} 29 struct node {30 int X, Y; 31} p [N]; 32 33 34 bool CMP (node, node B) {35 return. x <B. x; 36} 37 38 int DP [N] [N] [2]; 39 int sum [N]; 4 0 41 int main () {42 int N, V, X; 43 while (~ Scanf ("% d", & N, & V, & X) {44 for (INT I = 1; I <= N; I ++) {45 scanf ("% d", & P [I]. x, & P [I]. y); 46} 47 P [++ N]. X = x; 48 p [N]. y = 0; 49 sort (p + 1, p + 1 + N, CMP); 50 51 sum [0] = 0; 52 for (INT I = 1; I <= N; I ++) {53 sum [I] = sum [I-1] + P [I]. y; 54} 55 int TEM; 56 for (INT I = 1; I <= N; I ++) {57 if (P [I]. X = x) {58 TEM = I; 59 break; 60} 61} 62 63 for (INT I = 0; I <= N; I ++) {64 for (Int J = 0; j <= N; j ++) {65 DP [I] [J] [0] = DP [I] [J] [1] = inf; 66} 67} 68 DP [TEM] [TEM] [1] = DP [TEM] [TEM] [0] = 0; 69 70 for (INT I = TEM; i> = 1; I --) {71 for (Int J = TEM; j <= N; j ++) {72 if (I = J) continue; 73 74 DP [I] [J] [0] = min (DP [I] [J] [0], DP [I + 1] [J] [0] + (sum [I] + sum [N]-sum [J]) * (p [I + 1]. x-P [I]. x); 75 DP [I] [J] [0] = min (DP [I] [J] [0], DP [I + 1] [J] [1] + (sum [I] + sum [N]-sum [J]) * (p [J]. x-P [I]. x); 76 77 DP [I] [J] [1] = min (DP [I] [J] [1], DP [I] [J-1] [0] + (sum [I-1] + sum [N]-sum [J-1]) * (p [J]. x-P [I]. x); 78 DP [I] [J] [1] = min (DP [I] [J] [1], DP [I] [J-1] [1] + (sum [I-1] + sum [N]-sum [J-1]) * (p [J]. x-P [J-1]. x); 79} 80} 81 printf ("% d \ n", V * min (DP [1] [N] [0], DP [1] [N] [1]); 82} 83 return 0; 84}

 

Zoj3469 food delivery interval 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.