标签:准备 because min The php display 维护 efi 最大
P2365任务安排\((O(n^2)\)可过题)
一批任务的准备时间会影响从这批任务开始的所有任务的结束时间
\[f[i]=min_{0\le j<i}\{f[j]+SumT[i]*(SumC[i]-SumC[j])+s*(SumC[n]-SumC[j])\}\]
[BZOJ2726][SDOI202]任务安排(斜率优化+\(cdq\)分治)cdq分治我们不熟
double eps=1e-7;
int dcmp(double x){if(fabs(x) <= eps) return 0; return x > 0 ? 1 : -1;}
double Y(int x){return f[x]+a*s[x]*s[x]-b*s[x];}
double X(int x){return s[x];}
double slope(int i, int j){
double x1=X(i), y1=Y(i), x2=X(j), y2=Y(j);
return (y1-y2)/(x1-x2);
}
int q[Maxn], l, r;
void solve(){
n=read(); a=read(), b=read(), c=read(); for(int i=1; i <= n; i++) s[i]=s[i-1]+read();
l=r=1, q[1]=0;
for(int i=1; i <= n; i++){
while(l < r && dcmp(slope(q[l], q[l+1]) - 1.0*a*2*s[i]) > 0) l++;
f[i]=f[q[l]]+a*(s[i]-s[q[l]])*(s[i]-s[q[l]])+b*(s[i]-s[q[l]])+c;
while(l < r && dcmp(slope(q[r-1], q[r])-slope(q[r], i) <= 0)) r--;
q[++r]=i;
}
printf("%.0lf", f[n]);
}
#define a(i) (sum[i]+i)
#define b(i) (a(i)+L+1)
#define Y(i) (dp[i]+b(i)*b(i))
#define X(i) b(i)
#define slope(i, j) ((Y(i)-Y(j))/(X(i)-X(j)))
int q[N], head, tail;
void solve(){
n=read(), L=read(); head=tail=1;
for(int i=1; i <= n; i++){
sum[i]=sum[i-1]+read();
while(head < tail && slope(q[head], q[head+1]) < 2*a(i)) head++;
dp[i]=dp[q[head]]+(a(i)-b(q[head]))*(a(i)-b(q[head]));
while(head < tail && slope(i, q[tail-1]) < slope(q[tail-1], q[tail])) tail--;
q[++tail]=i;
}
printf("%lld\n", dp[n]);
}
int q[Maxn], l, r;
ll *f=f1, *g=g1;
double X(int i) {return S[i];}
double Y(int i) {return g[i]+S[i]*S[i];}
double slope(int i, int j){
double x1=X(i), y1=Y(i), x2=X(j), y2=Y(j);
return (y1-y2)/(x1-x2);
}
void solve(){
n=read(), m=read(); for(int i=1; i <= n; i++) S[i]=S[i-1]+read(), f[i]=S[i]*S[i];
for(int i=1; i < m; i++){
l=r=1; q[1]=i; swap(f, g);
for(int j=i+1; j <= n; j++){
while(l < r && slope(q[l], q[l+1]) <= 2.0*S[j]) l++;
f[j]=g[q[l]]+(S[j]-S[q[l]])*(S[j]-S[q[l]]);
while(l < r && slope(q[r], q[r-1]) >= slope(q[r], j)) r--;
q[++r]=j;
}
}
printf("%lld", f[n]*m-S[n]*S[n]);
}
标签:准备 because min The php display 维护 efi 最大
原文地址:https://www.cnblogs.com/zerolt/p/9262035.html