First, the f[x] represents the maximum value of a coupon that can be obtained by X-day, with a motion-gage equation:
$f [i]=max\{f[j]*a[i]+f[j]*b[i]/r[j]\}*r[i]/(R[i]*a[i]+b[i]) $,
Set $j <k$, $f [j]>f[k]$
$=> (F[j]/r[j]-f[k]/r[k])/(F[j]-f[k]) <-a[i]/b[i]$,
Make $g[i]=f[i]/r[i]$, there are $ (g[j]-g[k])/(F[j]-f[k]) <-a[i]/b[i]$
Describe each day as a point $ (f[i],g[i]) $ you can perform a slope optimization on a convex hull with two points.
CDQ divided by f[x] sorting, divide and conquer by ID, so that with a convex shell from left to right sweep again, you can update the entire interval answer.
1#include <iostream>2#include <algorithm>3#include <cstdio>4#include <cstdlib>5#include <cstring>6#include <cmath>7#include <ctime>8 9 using namespacestd;Ten One structnode A { - DoubleX,y,a,b,r,k;intPos; - BOOL operator< (ConstNode temp)Const{returnK>TEMP.K;} the}c[110000],temp[110000]; - - intn,head,tail,h[110000]; - Doublef[110000]; + - Const Doubleeps=1e-9; + A DoubleCalc (Const intXConst inty) at { - if(Fabs (c[x].x-c[y].x) <eps)return1e100; - return(C[X].Y-C[Y].Y)/(c[x].x-c[y].x); - } - - voidCDQ (Const intLConst intR) in { - if(l==R) to { +F[l]=max (f[l],f[l-1]); -c[l].y=f[l]/(C[l]. R*C[L]. A+C[L]. B); c[l].x=c[l].y*C[l]. R; the return ; * } $ Panax Notoginseng inti,mid=l+ (r-l) >>1); - the intL1=l,l2=mid+1; + for(i=l;i<=r;++i) A { the if(C[i].pos<=mid) temp[l1++]=C[i]; + Elsetemp[l2++]=C[i]; - } $ for(i=l;i<=r;++i) c[i]=Temp[i]; $ - CDQ (l,mid); - theTail=0, head=1; - for(i=l;i<=mid;++i)Wuyi { the while(tail>1&& Calc (h[tail-1],h[tail]) <calc (h[tail],i)) tail--; -h[++tail]=i; Wu } - for(i=mid+1; i<=r;++i) About { $ while(Head<tail && Calc (h[head],h[head+1]) >C[I].K) head++; -F[c[i].pos]=max (F[c[i].pos],c[h[head]].x*c[i]. a+c[h[head]].y*C[i]. B); - } - ACDQ (mid+1, R); + theL1=l;l2=mid+1; - for(i=l;i<=r;++i) $ { the if((c[l1].x<c[l2].x | | (Fabs (c[l1].x-c[l2].x) <eps && c[l1].y<c[l2].y+eps) | | L2>R) && l1<=mid) thetemp[i]=c[l1++]; the Else thetemp[i]=c[l2++]; - } in for(i=l;i<=r;++i) c[i]=Temp[i]; the return ; the } About the intMain () the { thescanf"%D%LF", &n,&f[0]); + for(intI=1; i<=n;++i) - { thescanf"%LF%LF%LF", &c[i]. A,&c[i]. b,&C[i]. R);BayiC[i].k=-c[i]. A/c[i]. b;c[i].pos=i; the } the -Sort (c+1, c+n+1); - theCDQ (1, n); the theprintf"%.3f\n", F[n]); the - return 0; the}
[bzoj1492] [NOI2007] CASH[CDQ Division; dp; slope optimization]