"CODEVS1258" Close the street lights

Source: Internet
Author: User

    • Title Description Description

Dorica got an interesting and well-paid job. Every morning he had to turn off the streetlights in his village. All the streetlights are set on the same side of a straight road.

Dorica at the party every 5 o'clock in the morning, and then he started turning off the lights. At first he stood next to a street lamp.

Each lamp has a given power of the light bulb, because the multi-card has a conscious energy-saving consciousness, he hoped that the total energy consumption in the case of the least to turn off all the lights.

Multi-card because too tired, so can only be 1m/s speed to walk. It doesn't take extra time to turn off the lights, because when he does, he can turn off the lights.

Write a program that calculates the minimum amount of energy required to turn off all lights in the case of a given street lamp setting, lamp power, and the starting position of the multiport card.

    • Enter a description input Description

The first line of the input file contains an integer n,2≤n≤1000 that represents the number of street lights in the village.

The second line contains an integer v,1≤v≤n that indicates the lamp number that Dorica started to turn off the lights.

In the next n rows, each row contains two integers separated by spaces D and W, used to describe the parameters of each lamp, where 0≤d≤1000,0≤w≤1000. D indicates the distance between the street lamp and the beginning of the village (expressed in meters), W represents the power of the bulb, that is, the amount of energy consumed in each second of the bulb. Streetlights are given in order.

    • Outputs description output Description

The first line of the output file, which is the only row, should contain an integer, which is the minimum value of the sum of energy consumed. Note that the results are smaller than 1,000,000,000.

    • Sample input to sample

4

3

2 2

5 8

6 1

8 7

    • Sample output sample outputs

56

/*f (i,j,0) means to turn off the light of the interval [i,j], which is the minimum power consumption of I, and F (i,j,1) to turn off the light of the interval [i,j], and the last is the minimum power consumption of J; F (i,j,0) =min{f (i+1,j,0) + (w[1..i]+w[j +1..N]) * (P[i+1]-p[i]), F (i+1,j,1) + (W[1..I]+W[J+1..N]) * (P[j]-p[i])} f (i,j,1) =min{f (i,j-1,0) + (w[1..i-1]+w[j: N]) * (P[j]-p[i]), F (i,j-1,1) + (W[1..I-1]+W[J). N]) * (P[j]-p[j-1])}*/#include<iostream>#include<cstdio>#include<cstring>using namespacestd;intk[1002];//Distanceinte[1002];//Power ConsumptionLong Longf[1002][1002][2];//Minimum EnergyintMinintXinty) {    if(x>y)returny; Else returnx;}intMain () {intn,m; scanf ("%d%d",&n,&m);  for(intI=1; i<=n;i++) {scanf ("%d%d",&k[i],&E[i]); E[i]+=e[i-1]; } memset (F,127,sizeof(f)); f[m][m][0]=f[m][m][1]=0;  for(intj=m;j<=n;j++)         for(inti=j-1; i>=1; i--) {f[i][j][1]=min (f[i][j-1][0]+ (K[j]-k[i]) * (e[n]+e[i-1]-e[j-1]), F[i][j-1][1]+ (k[j]-k[j-1]) * (e[n]-e[j-1]+e[i-1])); f[i][j][0]=min (f[i+1][j][0]+ (k[i+1]-k[i]) * (e[i]+e[n]-E[j]), F[i+1][j][1]+ (K[j]-k[i]) * (e[n]-e[j]+e[i])); } printf ("%ld", Min (f[1][n][0],f[1][n][1])); return 0;}

"CODEVS1258" Close the street lights

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.