Descriptionjsoi The Informatics team has a total of n candidates, numbered from 1 to N. For convenience, the JYY number is no. No. 0. Each candidate is recommended by a candidate Ri who has a smaller number than him. If ri=0 that the candidate is jyy himself. In order to ensure the harmony of the team, Jyy needs to ensure that if the candidate I is recruited, then the candidate Ri "must also be in the team." Of course, Jyy himself is always on the team. Each candidate has a combat value of pi ", there is also a recruiting fee si". Jyy wants to recruit a K-candidate (Jyy himself) to form a team that is the most cost-effective. That is, the total combat value of the K-Jyy selected candidates is the largest ratio of total recruitment costs.
Input one row contains two positive integers k and N. Next n lines, where the line I contains 3 integers si,pi,ri represents the recruitment fee for candidate I, the combat value and the referrer number. For 100% of data meet 1≤k≤n≤2500,0< "Si,pi" ≤10^4,0≤ri<i
Output outputs a single real number that represents the optimal ratio. The answer retains three decimal places.
Sample Input1 2
1000 1 0
1-1Sample Output0.001 Topic PortalThis rubbish problem ... I had a day of TM tuning. Tle to SpitOne Eye 01 score planning, then two points. Last Tree DPand then. There's a sick guy who's stuck with me. I 'll fill it in later.let's see how the Tle code is going to improve.Thank you! The code is as follows:
#include <cmath>#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>#defineEPS 1e-4#defineINF 1<<25using namespacestd;structnode{intX,y,next;} a[4100000];intlen,last[4100000];voidInsintXinty) {Len++; a[len].x=x;a[len].y=y; A[len].next=last[x];last[x]=Len;}intn,m;Doubletot[2510],cost[2510];intd[2510];Doublef[2510][2510];intmem[2510];voidTREEDP (intXDoubleC) {f[x][0]=0.0; f[x][1]=tot[x]-c*cost[x];mem[x]=1; for(intk=last[x];k;k=A[k].next) { inty=a[k].y; TREEDP (Y,C); for(intI=m;i>1; i--) for(intj=0; j<=mem[y];j++) { if(i-j>=1) F[x][i]=max (f[x][i],f[y][j]+f[x][i-J]); Else Break; } Mem[x]+=Mem[y]; }}BOOLCheckDoubleC) {memset (mem,0,sizeof(MEM)); Memset (F,-inf,sizeof(f)); TREEDP (0, C); if(f[0][m]>=0.0)return true; return false;}intMain () {Freopen ("a.in","R", stdin); Freopen ("a.out","W", stdout); scanf ("%d%d", &m,&n); len=0; for(intI=1; i<=n;i++) {scanf ("%lf%lf%d",&cost[i],&tot[i],&D[i]); Ins (d[i],i); } DoubleL=0.0, r=3.0; Doublemid,ans=0.0; while(l<r) {Mid= (l+r)/2; if(check (mid) = =true) {ans=mid,l=mid+EPS;} Elser=mid-EPS; } printf ("%.3lf\n", ans); return 0; }
By_lmy
BZOJ4753: [Jsoi2016] Best Group