P1220 off the street light

Source: Internet
Author: User

Transmission DoorIdeas:

It is obvious that the interval motion regulation. Set f [i] [j] [K] to indicate that the position of the old Zhang is located [(k=0, at i), (K=1, at J)] when the street light from I to J is closed.

You can conclude that the transfer equation is:

f [i] [j] [0] = min (f [i+1] [j] [0] + cal (), F [i+1] [j] [1] + cal ());

f [i] [j] [1] = min (f[i] [j-1] [0] + cal (), f[I [j-1] [1] + cal ());

Note: Cal ()-pseudo code calculates the power consumed by street lights that are not closed when transferred from the previous interval.

Standard Process:
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cstdlib>#include<cmath>#include<string>#include<vector>#include<stack>#include<map>#include<Set>#include<queue>#include<deque>using namespacestd;#defineMAXN 60#defineINF 0x3fintSUM[MAXN],A[MAXN],B[MAXN];//A record position, B record powerintf[maxn][maxn][2];intN,c;inlineintRead () {intKr=1, xs=0; Charls; LS=GetChar ();  while(!isdigit (LS)) {        if(! (ls^ $)) KR=-1; LS=GetChar (); }     while(IsDigit (LS)) {xs= (xs<<1) + (xs<<3) + (ls^ -); LS=GetChar (); }    returnxs*KR;}intMain () {n=read (); c=read ();  for(intI=1; i<=n;i++) {A[i]=read (); B[i]=read ();//read into the distance of this lamp, the powersum[i]=sum[i-1]+b[i];//can take advantage of the prefix and quickly find the power from I to J and (below the moving gauge transfer to be used)} memset (F,inf,sizeof(f)); f[c][c][0]=f[c][c][1]=0;//just started at the point where the old Zhang was directly clear 0     for(intL=2; l<=n;l++)//enumeration Interval Length         for(intI=1; i+l-1<=n;i++)//Enumerate left endpoints        {            intj=i+l-1; f[i][j][0]=min (f[i+1][j][0]+ (a[i+1]-a[i]) * (Sum[i]+sum[n]-sum[j]), f[i+1][j][1]+ (A[j]-a[i]) * (sum[i]+sum[n]-sum[j])); f[i][j][1]=min (f[i][j-1][0]+ (A[j]-a[i]) * (sum[i-1]+sum[n]-sum[j-1]), f[i][j-1][1]+ (a[j]-a[j-1]) * (sum[i-1]+sum[n]-sum[j-1]));//can refer to pseudo-code} printf ("%d\n", Min (f[1][n][0],f[1][n][1]));//Outputreturn 0;}

P1220 off the street light

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.