P3699 Pizza Delivery |
Time limit:-MS space limit: 65536 KB |
Evaluation instructions: time limit 2000ms |
|
Problem Description
The boss opened a pizza shop and one day suddenly received orders from N customers.
Where the boss of the city only a straight street, we can think of it as the axis, where the location of 0 is the owner of the pizza shop, the first customer is located in the Pi, each customer's location is different. If the boss sends pizza to the first customer, the customer will pay Ei-ti, which TI is the moment the boss arrives at his home. Of course, if arrive too late, will make ei-ti<0, at this time, what boss can choose not to give him to deliver meal, lest he turn to find what boss wants money.
HO Boss Store only a delivery car (distance per unit of time travel unit length), so only round-trip delivery, as shown below is a line, the figure of the first line is the position pi, the second line is EI.
Your task is to help the boss calculate the maximum benefit. Input Format
First line, an integer n
The second line, an integer of n space intervals, gives the position of each customer from left to right pi, i.e. P1,P2,......, Pn
The third line, an integer of n space intervals, gives each customer a corresponding EI, the e1,e2,......, En output format , from left to right
A row, an integer, that represents the best proceeds of the sample input 1
5
-6-3-1 2 5
27 10 2) 5 20
Sample Output 1
32
Sample Input 2
6
1 2 4 7 11 14
3 6 2 5 18 10
Sample Output 2
13
Sample Input 3
11
-14-13-12-11-10 1 2 3 4 5 100
200 200 200 200 200 200 200 200 200 200 200
Sample Output 3
1937
Tips
1≤n≤100
-100,000≤pi≤100,000 and Pi!=0
0< ei≤100,000
#include <cstdio> #include <iostream> #include <algorithm> #include <cstdlib> #include <
Cstring> using namespace std;
int f[205][205][205][2];
BOOL Mark[205][205][205][2];
int n;
int Pos[205],e[205],start;
int dp (int l,int r,int cnt,int p) {int i;
if (Mark[l][r][cnt][p]) return f[l][r][cnt][p];
Mark[l][r][cnt][p]=true;
if (cnt==0) return f[l][r][cnt][p]=0;
if (p==0) {for (i=1;i<l;i++) {F[l][r][cnt][p]=max (F[L][R][CNT][P],DP (i,r,cnt-1,0) +e[i]-cnt*abs (Pos[l]-pos[i]));
} for (i=r+1;i<=n+1;i++) {F[l][r][cnt][p]=max (F[L][R][CNT][P],DP (l,i,cnt-1,1) +e[i]-cnt*abs (Pos[l]-pos[i]));
}} else{for (i=1;i<l;i++) {F[l][r][cnt][p]=max (F[L][R][CNT][P],DP (i,r,cnt-1,0) +e[i]-cnt*abs (Pos[r]-pos[i]));
} for (i=r+1;i<=n+1;i++) {F[l][r][cnt][p]=max (F[L][R][CNT][P],DP (l,i,cnt-1,1) +e[i]-cnt*abs (Pos[r]-pos[i]));
}} return f[l][r][cnt][p];
} int main () {int i,j,ans=0;
start=0;
cin>>n;
for (i=1;i<=n+1;i++) {cin>>pos[i]; if (POS[i]>0&&start==0) {start=i;
Pos[i+1]=pos[i];
pos[i]=0;
i++;
}} for (i=1;i<=n+1;i++) {cin>>e[i];
if (start==i) {e[i+1]=e[i];
e[i]=0;
i++;
}} for (i=0;i<=n;i++) {Ans=max (ANS,DP (start,start,i,0));
} cout<<ans; }