[POJ1180] Batch Scheduling slope Optimization dp

Source: Internet
Author: User

Description

there is a sequence of N jobs to being processed on the one machine. The jobs be numbered from 1 to N, so the the sequence is,..., N. The sequence of jobs must be partitioned to one or more batches, where each batch consists the consecutive jobs in the SE Quence. The processing starts at time 0. The batches is handled one by one starting from the first batch as follows. If A batch B contains jobs with smaller numbers than batch C and then batch B is handled before batch c. The jobs in a batch is processed successively on the machine. Immediately after all the jobs in a batch is processed, the machine outputs the results of the "all the" and "that" batch. The output time of a job j is the time when the batch containing J finishes.

A setup time S is needed to set up the machine for each batch. For each job I, we know their cost factor Fi and the time Ti required to process it. If A batch contains the jobs x, X+1,..., X+k, and starts at time t, then the output time of every job in this batch is T + S + (tx + tx+1 + ... + tx+k). Note that the machine outputs the results of all jobs in a batch at the same time. If the output time of job I is Oi, it cost is Oi * Fi. For example, assume that there is 5 jobs, the setup time S = 1, (T1, T2, T3, T4, T5) = (1, 3, 4, 2, 1), and (F1, F2, F3, F4, F5) = (3, 2, 3, 3, 4). If The jobs is partitioned into three batches {1, 2}, {3}, {4, 5}, then the output times (O1, O2, O3, O4, O5) = (5, 5, 10 , (+) and the costs of the jobs are (at a), respectively. The total cost for a partitioning are the sum of the costs of all jobs. The total cost of the example partitioning above is 153. 

You is to write a program which, given the batch setup time and a sequence of jobs with their processing times and Cost factors, computes the minimum possible total cost.
looking at the form and data range of this problem, slope optimization is already obvious.
But when we wanted to write the transfer, we had a problem ...Calculate the time that is spent in the previous phase of the current costand it doesn't matter how much time it takes to spend it .to ensure correctness can only write a seemingly uncomfortable two-dimensional DPwe will think that the time before processing will affect the current so bad treatment, then we can let the present time to affect the previous results? The answer is yes, we can define the state in turn. Use f[i] to denote I. n the cost and. f[i]=f[j]+ (S*t[i]-t[j]) *f[i]    T[i] means I.. N Part processing time and, f[i] means I.. n the part weight value and. As a result, the problem is much clearer. can be performed with normal slope optimization. set i<j<k set at this time fetch J ratio k Good, then list inequalities f[j]+ (T[i]-t[j]) *f[i]<f[k]+ (T[i]-t[k]) *f[i]    to simplify f[i]> (F[j]-f[k])/(T[j]-t[k])    This is the slope expression we are familiar with. Set it to G[j,k]
maintains a convex monotone sequence. when solving the current answer, we can tell by G which points are betterIt is easy to see that when the sequence monotonicity is maintained, the (G[j,k]<f[i]) is satisfied with 00000011111That is, when we meet the first 1 position, J is the state we are asking for. the solution is transferred directly according to the introduced equation. then we will add the current point and maintain monotonicity at the same time.   The code is very short feeling very beautiful >_<
Program poj1180;Constmaxn=10010;varI,head,tail,n,s:longint; opt,dp,f,t:array[-1.. Maxn]of int64;function g (x,y:longint): Extended;begin exit ((Dp[x]-dp[y])/(t[x]-t[y]));    End;begin READLN (n);    READLN (s);  fori:=1to n Doreadln (T[i],f[i]);  fori:=n-1Downto1  DoBegin Inc (T[i],t[i+1]); Inc (F[i],f[i+1]);    End T[n+1]:=0; f[n+1]:=0; Head:=1; tail:=1; opt[1]:=n+1;DP [n+1]:=0;  forI:=n Downto1  Dobegin while(Head<tail) and (g (opt[head+1],opt[head]) <f[i]) DoInc (head); Dp[i]:=dp[opt[head]]+ (S+t[i]-t[opt[head]) *F[i];  while(Head<tail) and (g (opt[tail],opt[tail-1]) >g (I,opt[tail])) DoDec (tail); Inc (tail); Opt[tail]:=i;    End Writeln (dp[1]); end.

[POJ1180] Batch Scheduling slope Optimization dp

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.