Luo Gu P2466 [SDOI2008] Sue ball

Title 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 horizontal plane where the initial position of the 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 Format

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 Format

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

Sample input and output

Entry
3 0
-4 -2 2
22 30 26
1 9 8
Export 
0.000

General idea

First %%%  Bartholomew big brother and his explanations

Then see the need to calculate the highest score, there are some restrictions, the first thought dp

Equation dp [1] [i] [j] denotes the i to j then finished egg position j in the resultant fraction, dp [0] [i] [j] represents the bonding position after the resulting fraction i

Because different every time then finished, other different egg drop height is no way to continue to shift down, so after Gangster inspired to think of each dp value directly count the scores of other eggs in the loss of access time i to j , such an action would facilitate the transfer of! ! !

First dp [0] [i] [j], because he was in position i, so it must be transferred from dp [0/1] [i + 1] [j] over, minus the ball speed and other multiplied by the time (i.e. the time i ball), and wherein the speed may be pre-prefix and out.

Then dp [1] [i] [j] Similarly

Maximum final answer takes dp [0] [1] [n] and dp [1] [1] [n] is

Transfer equation:
DP [0] [I] [J] = max (DP [0] [+. 1 I] [J] - (A [I +. 1] .x - A [I] .x) * (other balls and speed), dp [1] [i + 1] [j] - (a [j] .x - a [i] .x) * ( speed and other balls))

dp [1] [i] [j] = max (dp [0] [i] [j-1] - (a [j] .x - a [i] .x) * (speed and other balls), dp [1] [i] [j-1] - (a [j] .x - a [j-1] .x) * (and other balls speed))

PS: For insurance purposes, all coordinates plus the absolute value of the subtraction is recommended, do not forget to answer the original score thousandth

Attach Code:

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
#define MAXN 100100
int n, m, cnt, sum[1100], dp[2][1100][1100];
struct node
{
	int x, y, v;
}a[MAXN];
bool cmp(node x, node y)
{
	return x.x < y.x;
}
int main()
{
	scanf("%d%d",&n,&a[0].x);
	for(int i=1;i<=n;i++) scanf("%d",&a[i].x);
	for(int i=1;i<=n;i++) scanf("%d",&a[i].y);
	for(int i=1;i<=n;i++) scanf("%d",&a[i].v);
	sort(a+1,a+n+1,cmp); 
	for(int i=1;i<=n;i++) sum[i] = sum[i-1] + a[i].v;
	for(int i=1;i<=n;i++) dp[0][i][i] = dp[1][i][i] = a[i].y - sum[n] * abs(a[i].x - a[0].x);//, printf("%d\n",dp[0][i][i]);
	//就一个球的话需要从初始位置走过去 
	for(int len = 2;len<=n;len++)
	{
		for(int i=1;i<=n-len+1;i++)
		{
			int j = i+len-1;
			dp[0][i][j] = max(dp[1][i+1][j] - abs(a[j].x-a[i].x) * (sum[i] + sum[n] - sum[j]), dp[0][i+1][j] - abs(a[i+1].x - a[i].x) * (sum[i] + sum[n] - sum[j])) + a[i].y;
			dp[1][i][j] = max(dp[1][i][j-1] - abs(a[j].x-a[j-1].x) * (sum[i-1] + sum[n] - sum[j-1]), dp[0][i][j-1] - abs(a[j].x - a[i].x) * (sum[i-1] + sum[n] - sum[j-1])) + a[j].y;
		}//sum为前缀和统计答案,计算答案 
	}
	int Max = max(dp[0][1][n], dp[1][1][n]);
	printf("%.3lf\n",(double)Max * 0.001);
	
	return 0;
}

Guess you like

Origin www.cnblogs.com/tuihuaddeming/p/11620736.html