From the lighthouse to the left, light one, and all the lighthouses in the left Di range are destroyed. You can now press a lighthouse at the far right, with any range of attacks, and ask at least a few lighthouses to leave at the end.
With the DP blind. Look at the code specifically.
#include"Cstdio"#include"Queue"#include"Cmath"#include"Stack"#include"iostream"#include"algorithm"#include"CString"#include"Queue"#include"Vector"#definell Long Longusing namespacestd;Const intMAXN =1e6;Const intMaxe =200500;Const intINF =0x3f3f3f;structnode{intb;} X[MAXN];intSUM[MAXN];intdp[maxn*Ten];BOOLCMP (node X,node y) {returnx.a<y.a;}intMain () {intN;SCANF ("%d",&N); intmaxv=-1; for(intI=0; i<n;i++) {scanf ("%d%d",&x[i].a,&x[i].b); MAXV=Max (MAXV,X[I].A); } if(n==1) {printf ("0\n"); return 0; } sort (X,x+n,cmp); dp[x[0].a]=1; for(inti=x[0].a+1, j=1; i<=maxv;i++){ if(i>=x[j].a) { intt=x[j].a-x[j].b-1; if(t>=0) dp[i]=dp[t]+1; Elsedp[i]=1; J++; } Elsedp[i]=dp[i-1]; } intans=INF; for(inti=x[0].a;i<=maxv;i++) Ans=min (ans,n-Dp[i]); //cout<<i<< ' \ t ' <<dp[i]<<endl;printf"%d\n", ans); return 0;}
View Code
Codeforces 608C: (DP)