2037: [Sdoi2008] Sue beads (section DP)

2037: [Sdoi2008] Sue ball

Time Limit: 10 Sec  Memory Limit: 64 MB
Submit: 945  Solved: 538
[Submit][Status][Discuss]

Description

Sue and Sandy recently hooked on a computer game, the story of this game is made on the beauty and mystery of the sea and full of excitement, Sue has a compact and lightweight boat. However, Sue's goal is not as a pirate, but to collect eggs floating in the air, Sue has a secret weapon, as long as she would a boat out to just below the egg, and then use the secret weapon will be able to collect the eggs in an instant . However, eggs have a Charisma, Charisma this egg will be reduced in the air landing time with, Sue To get more points, you must try to collect the eggs at a time of high Charisma, and if an egg falls into the sea it's Charisma will become a negative number, but this does not affect the interest of Sue, because every egg is different, Sue want to collect all the eggs. But Sandy did not so romantic Sue, Sandy want to get as many points, in order to solve this problem, the first game he has become an abstract model as follows: Sue initial position where the horizontal x-axis. Beginning the air with N egg, for the i th eggs, his initial position indicated by the integer coordinates (xi, yi), after the start of the game, it is uniform along the y-axis negative direction falling at a speed of vi unit distance / unit time. The initial position of Sue is (x0, 0), Sue can be moved in the positive direction of the x-axis or the negative direction, the moving speed Sue is a unit distance / unit of time, using the secret weapon to give a egg is instantaneous, the score for the current egg thousandth y coordinates. Now, Sue and Sandy ask you to help, in order to meet Sue and Sandy respective goals, you decide to collect the highest score on the basis of all the eggs on, get.

Input

The first two acts of integers N, x0 separated by a space, the number of eggs showing the initial position of Sue. The second behavior N integers xi, each of the two numbers separated by a space, the i-th horizontal axis represents the i-th initial egg. The third row of the N integers yi, every two numbers separated by a space, the i-th initial ordinate represents the i-th eggs. Fourth line VI N integers, every two numbers separated by a space, the number i represents the i-th eggs uniform speed along the y-axis negative direction of falling.

Output

A real number, rounded to three decimal places, to collect all the eggs on the basis, can get the highest score.

Sample Input

3 0
-4 -2 2
22 30 26
1 9 8

Sample Output

0.000


Data range:
N <= 1000, data for 100%. -10 ^ 4 <= xi, yi , vi <= 10 ^ 4
 
. 1 #include <the iostream>
 2 #include <cstdio>
 . 3 #include <CString>
 . 4 #include <the cstdlib>
 . 5 #include <algorithm>
 . 6 #include <The iomanip>
 . 7  #define LL Long Long
 . 8  
. 9  the using  namespace STD;
 10  
. 11  const  int MAXN = 1005 ;
 12 is  Double DP [MAXN] [MAXN] [ 2 ];    // value minus the value of the loss values represent the meaning ultimately get get the total value of all - the loss of value 
13 is  int SUM [ MAXN];
 14  int n-, m;
 15  const int INF=-0x3f3f3f3f;
16 
17 struct Node{
18     int x,y,v;
19     bool operator<(const Node&X) const{
20         return x<X.x;
21     }
22 }A[maxn];
23 
24 int main(){
25     ios::sync_with_stdio(false);
26     memset(dp,INF,sizeof(dp));
27     cin>>n>>m;
28     for(int i=1;i<=n;i++) cin>>A[i].x;
29     for(int i=1;i<=n;i++) cin>>A[i].y;
30     for(int i=1;i<=n;i++) cin>>A[i].v;
31 
32     sort(A+1,A+1+n);
33     for(int i=1;i<=n;i++) sum[i]=sum[i-1]+A[i].v;
34     for(int i=1;i<=n;i++){
35         dp[i][i][0]=A[i].y-abs(A[i].x-m)*sum[n];
36         dp[i][i][1]=A[i].y-abs(A[i].x-m)*sum[n];
37     }
38     for(int len=2;len<=n;len++){
39         for(int i=1;i+len-1<=n;i++){
40             int j=i+len-1;
41             dp[i][j][0]=max((dp[i+1][j][0]+A[i].y-(A[i+1].x-A[i].x)*(sum[n]-sum[j]+sum[i])),dp[i+1][j][1]+A[i].y-(A[j].x-A[i].x)*(sum[n]-sum[j]+sum[i]));
42             dp[i][j][1]=max((dp[i][j-1][0]+A[j].y-(A[j].x-A[i].x)*(sum[n]-sum[j-1]+sum[i-1])),dp[i][j-1][1]+A[j].y-(A[j].x-A[j-1].x)*(sum[n]-sum[j-1]+sum[i-1]));
43         }
44     }
45     cout << fixed << setprecision(3) << max(dp[1][n][0],dp[1][n][1])/1000.0 << endl;
46     return 0;
47 
48 }
View Code

 

Guess you like

Origin www.cnblogs.com/qq-1585047819/p/11806830.html