Bzoj 2726: [SDOI2012] Task schedule [slope optimization DP-sub-calculation cost]

Source: Internet
Author: User

2726: [SDOI2012] Task schedule time limit:10 Sec Memory limit:128 MB
submit:868 solved:236
[Submit] [Status] [Discuss] There are n tasks on the description machine that need to be processed, and they form a sequence. These tasks are labeled as 1 to N, so the sequence is arranged in 1,2,3...N. These n tasks are divided into batches, each containing several contiguous tasks. Starting at 0, these tasks are processed in batches, and the time required to complete the task of the first I is TI. Before each batch of tasks starts, the machine needs to start the time S, and the time required to complete the task is the sum of time for each task. Note that the same batch of tasks will be completed at the same time. The cost per task is the time it is completed multiplied by a cost factor fi. Please identify a grouping scheme to minimize the total cost. Input the first row of two integers, n,s. The next n rows are two integers per line, Ti,fi. Output an integer for the answer you are seeking. Sample Input5 1
1 3
3 2
4 3
2 3
1 4
Sample Output153 time is negative?! The state equation Zhang is usually optimized with slope (f[i]=f[j]+ (j+1...i+ what) * What is the thing )how to calculate the cost? The most annoying is the s, so you can calculate the cost of S to the back in advance {Similar title: http://www.cnblogs.com/candy99/p/6048599.html http://www.cnblogs.com/candy99/p/5968110.html} f[i]=min{f[j]+s* (P[n]-p[j]) +t[i]* (P[i]-p[j])}: P is the cost, T and P both handle prefixes andand then, you get:j<k pj<pk t[i]> (F[k]-f[j])/(P[k]-p[j])-S k more excellentslope (x, y) >slope (y,z) when Y is not optimal, lower convex hullP monocytogenes, but T has a negative number is not monotonous, so to two points slope (j,j+1) >=a[i] JThen there is a problem, the direct calculation slope will explode the size of double, so manually go to the score (that's why I really don't know why WA) PS: I'm a riddle to see why the elements in the array automatically change and suddenly realize that the size of the arrays has been forgotten .... The mysterious overflow actually modifies the previous array element.
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespacestd;Const intn=1e6+5; typedefLong LongLl;inlineintRead () {CharC=getchar ();intx=0, f=1;  while(c<'0'|| C>'9'){if(c=='-') f=-1; c=GetChar ();}  while(c>='0'&&c<='9') {x=x*Ten+c-'0'; c=GetChar ();} returnx*F;}intn,s;intQ[n],head,tail;ll T[n],p[n],f[n];//inline double slope (int j,int k) {//return (double) (f[k]-f[j])/(double) (P[k]-p[j])-S;//}voiddp () { for(intI=1; i<=n;i++){        intL=0, r=tail;//While (l<r) {//int mid= (l+r) >>1;//if (slope (q[mid],q[mid+1]) >= (double) t[i]) R=mid;//else l=mid+1;//        }         while(l<R) {            Long LongMid= (L+R)/2; if(f[q[mid+1]]-f[q[mid]]>= (S+t[i]) * (p[q[mid+1]]-p[q[mid]]) r=mid; ElseL=mid+1; }        intj=Q[l]; F[i]=f[j]+t[i]* (P[i]-p[j]) +s* (p[n]-p[j]);//while (Head<tail&&slope (Q[tail-1],q[tail]) >slope (q[tail],i)) tail--;//q[++tail]=i;         while(head<tail&& (F[i]-f[q[tail]) * (p[q[tail]]-p[q[tail-1]]) <= (f[q[tail]]-f[q[tail-1]]) * (P[i]-p[q[tail])) tail--; q[++tail]=i; } printf ("%lld", F[n]);}intMain () {//freopen ("In.txt", "R", stdin);N=read (); s=read ();  for(intI=1; i<=n;i++) t[i]=t[i-1]+read (), p[i]=p[i-1]+read (); DP ();}

Bzoj 2726: [SDOI2012] Task schedule [slope optimization DP-sub-calculation cost]

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.