Portal
When you see the data range, you know it's search or pressure DP
Well, a wave of complexity search seems to pass the limit data.
Engage the pressure
Set f [i] to indicate that the state of all pigs is the minimum number of launches required for I (binary 1 means dead, 0 indicates not dead)
Set p [i] [j] the state of the pig which passes through the parabola of the first pig and the first J Pig (can be $n^2$ pretreated, the solution equation will be.) )
Find the first undead pig I, and then enumerate all the other pigs that are not dead, J, to transfer:
f [I|p [i] [j]] = min (f [i|p [i] [j]],f [i] + 1)
No n^2 enumeration of all two pigs p [i] [j], because the first pig will die now, so there's no difference.
Also consider the case of a pig only: f [i| ( 1<<i-1)] = min (f[i| ( 1<<i-1)],f [i] +1)
Pay attention to the a<0 of parabolic analytic formula, remember to judge the legitimacy
#include <iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>using namespaceStd;typedefLong LongLl;inlineintRead () {intx=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9') {if(ch=='-') f=-1; Ch=GetChar ();} while(ch>='0'&&ch<='9') {x= (x<<1) + (x<<3) + (ch^ -); Ch=GetChar ();} returnx*F;}Const Doubleeps=1e-8;Const intn=300007;intn,m,t;structdata{Doublex, y;} d[ -];DoubleA,b;inlinevoidSlove (DoubleX1,DoubleY1,DoubleX2,Doubley2)//Solution Equation{ Doublet=x2*x2/x1/X1; b= (y2-y1*t)/(X2-X1*T); A= (y1-x1*b)/x1/x1;}intp[ -][ -];intF[n];voidPre () {memset (P,0,sizeof(p)); Memset (F,0x3f,sizeof(f)); f[0]=0;//Remember to initialize for(intI=1; i<=n;i++) for(intj=i+1; j<=n;j++) { if(Fabs (d[i].x-d[j].x) <eps)Continue;//if the horizontal axis is the same, no solutionSlove (D[I].X,D[I].Y,D[J].X,D[J].Y); if(a>=0)Continue;//judging legality for(intk=1; k<=n;k++)if(Fabs (A*D[K].X*D[K].X+B*D[K].X-D[K].Y) <=eps)/*If the parabolic line passes through the Pig K, record it .*/P[i][j]|= (1<<k-1); }}intMain () {T=read (); while(t--) {n=read (); m=read (); for(intI=1; i<=n;i++) scanf ("%LF%LF",&d[i].x,&d[i].y); Pre (); intMx= (1<<n)-1, POS; for(intI=0; i<=mx;i++) { for(intj=0; j<n;j++)if( ! ((I>>J) &1)) {pos=j; Break; }//find the first pig that's not dead.F[i| (1<<pos)]=min (f[i| (1<<pos)],f[i]+1);//separately considered for(intj=pos+1; j<n;j++)//consider with other pigs if( ! ((I>>J) &1)) f[i|p[pos+1][j+1]]=min (f[i|p[pos+1][j+1]],f[i]+1);//Note the subscript of P} printf ("%d\n", f[mx]); } return 0;}
P2831 Angry Birds