Tiered DP: Paradise (Heaven)

Source: Internet
Author: User

Title Description
Every person to go to heaven has to undergo a test, of course, including small x, small x began his strange Journey into heaven. There are 18 levels of hell, heaven is like hell, there are many layers, there are n layers of heaven. From the bottom to the next is the 1,2,3,...,n layer, each layer of heaven is a stretch of the floor, in the floor can be arbitrarily moved, layer and layer is a parallel relationship, each floor is a person can not pass through the material composition, fortunately each floor has and only 1 people can pass the hole.
We can consider the small x and the hole, as well as the balloon shops mentioned below as points, coordinates are two-dimensional. Small x starts in the first
3
1-storey (0,0).
Small x of the weight of M, layer I and the i+1 layer between the special gas can float the weight of WI, each layer of the ground scattered a number of balloon shops, a number of balloon shops can be at the same point, each balloon can float the weight is 1, go to a balloon shop can only pick up a balloon, can not be in a balloon shop to collect balloons Of course you can run back and forth between the two balloon stores, each with an unlimited number of balloons. The first layer of the balloon can only be used when the layer I enters the i+1 layer, when the small x in layer I, only the position of the i+1 layer hole (in other locations will not float), and its own weight is less than equal to the balloon and special gas float the sum of the weight, you can enter the I+1 layer. Little X wants to know what the minimum length he's going to get to the nth level? The problem is guaranteed to be solved.
Input file
Line 1th: three positive integers n,m,q (Q indicates balloon shop)
Line 2nd: Total (N-1) integer, each two number describes the 1 hole coordinates, the xi,yi represents the position of the entrance of the i+1 layer (xi,yi).
Line 3rd: A total of N-1 integers, number i is WI.
Next Q line, three integers per line x, Y, Z, indicates that the z layer has a balloon store with coordinates of (x, y)
Output file
1 real number L, reserved two decimal places, indicating the minimum length of a small x to go.
Sample input
3 10 4
0 0 1 2
9 0
0 1 1
2 3 1
0 1 2
1 1 2
Sample output
13.00
Comments
"Sample Interpretation"
On the first floor from (0,0) to (0,1) Get 1 balloons and return (0,0) can reach the second floor. Length: 2.00
On the second floor, from (0,0) to (0,1) to collect balloons, and then to collect balloons, two points to run back and forth, the 5th time to arrive (at) the number of balloons to reach 10, to reach the 3rd level end. Length: 11.00
Total Length: 13.00
"Data Range"
2<=n<=100
The number of balloon shops per floor is not more than 50.
0&LT;=M&LT;=100, 0<=wi<=100
Coordinate -3000<=x,y<=3000

It can be seen that each layer and the other layers are not affected.
For the X-layer, a total of number[x] balloon shop, gas buoyancy is air[x], that is, to receive m-air[x] a balloon
F[I,J] Indicates the receipt of the first J balloon at the first balloon.
F[i,j]:=min (F[k,j-1]+dist[i,j]) {i<>k}
F[i,1]:= the distance from the beginning to each balloon shop
The smallest moving distance of the X-layer is the distance from the min{f[i,m-air[x]]+ endpoint to i}

And can no longer see the data range wrong.

Code
var n,m,q:longint;
Pole:array[1..200]of Record
X,y:longint;
End
Air:array[1..200]of Longint;
Number:array[1..200]of Longint;
Position:array[1..200,1..60]of Record
X,y:longint;
End
F:array[1..1010,1..1000]of Double;
Dist1,dist2:array[1..100]of Double;
Dist:array[1..100,1..100]of Double;
Ii,i,j,k:longint;
Sx,sy,fx,fy:longint;
X,y,z:longint;
min,ans:double;
temp:double;
Begin
READLN (N,M,Q);
For i:=2 to N do
Read (POLE[I].X,POLE[I].Y);
For I:=1 to N-1 do
Read (Air[i]);
Fillchar (position,sizeof (position), 0);
Fillchar (number,sizeof (number), 0);
For I:=1 to Q do
Begin READLN (x, y, z);
Inc (Number[z]);
Position[z,number[z]].x:=x;
Position[z,number[z]].y:=y;
End
ans:=0;
sx:=pole[1].x;
SY:=POLE[1].Y;
For Ii:=1 to N-1 do
Begin IF Air[ii]<m
Then BEGIN Fillchar (Dist1,sizeof (Dist1), 0);
Fillchar (Dist2,sizeof (Dist2), 0);
Fillchar (dist,sizeof (Dist), 0);
For I:=1 to Number[ii] do
Dist1[i]:=sqrt (SQR (POSITION[II,I].X-SX) +
Sqr (Position[ii,i].y-sy));
For I:=1 to Number[ii] do
For J:=1 to Number[ii] do
Dist[i,j]:=sqrt (SQR (position[ii,i].x-position[ii,j].x) +
Sqr (POSITION[II,I].Y-POSITION[II,J].Y));
For I:=1 to Number[ii] do
For J:=1 to M-air[ii] do
f[i,j]:=maxint*5000;
For I:=1 to Number[ii] do
F[i,1]:=dist1[i];
fx:=pole[ii+1].x;
FY:=POLE[II+1].Y;
For I:=1 to Number[ii] do
Dist2[i]:=sqrt (SQR (POSITION[II,I].X-FX) +
Sqr (Position[ii,i].y-fy));
For j:=2 to M-air[ii] do
For I:=1 to Number[ii] do
For K:=1 to Number[ii] do
if (F[i,j]>f[k,j-1]+dist[i,k]) and (i<>k)
Then F[i,j]:=f[k,j-1]+dist[i,k];
Min:=maxlongint;
For I:=1 to Number[ii] do
If Min>f[i,m-air[ii]]+dist2[i]
Then Min:=f[i,m-air[ii]]+dist2[i];
Ans:=ans+min;
sx:=pole[ii+1].x;
SY:=POLE[II+1].Y;
End
else begin fx:=pole[ii+1].x;
FY:=POLE[II+1].Y;
Ans:=ans+sqrt (Sqr (SX-FX) +SQR (sy-fy));
sx:=pole[ii+1].x;
SY:=POLE[II+1].Y;
End
End
Writeln (Ans:0:2);

End.

Tiered DP: Paradise (Heaven)

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.