Test instructions: BC DIV1 1003 (Chinese side)
Analysis: Do not consider multiplying the result by 1e6 first. Set Dp[i] The maximum damage exponent that can be obtained for the state of the former I lattice.
Then we can enumerate each bomb, the distance to the left of the bomb, and the distance to the extension.
Set the bomb damage interval for [L, R], then dp[r] = Dp[l-1] + log2 (r-l + 1). The answer is dp[n-1]. Don't forget to take the final rounding down.
Note: I have a little explanation for the official puzzle, Dp[i] represents the maximum damage index that can be obtained for the former I lattice
However, when updating, it should be noted that there is a fake n bombs, the location of the first bomb is o[i]
So consider handling to the first bomb, he can update the DP[J] is limited, o[i]<=j<o[i+1], because the explosion of a bomb area can not cross another bomb
Update dp[j] also dp[k] is limited, o[i-1]<=k<=o[i], the truth is the same
And then it looks like a triple loop, actually very small.
Then there is a small optimization, which puts log2 (1-2000) out in advance, because this function is very slow
#include <cstdio>#include<cstring>#include<queue>#include<cstdlib>#include<algorithm>#include<vector>#include<cmath>using namespaceStd;typedefLong LongLL;Const intn=2e3+5;Const intinf=0x3f3f3f3f;intO[n];DoubleDp[n],val[n];intMain () { for(intI=1; i<=2001;++i) val[i]=log (i)/log (2); intT; scanf ("%d",&T); while(t--){ intn,m; scanf ("%d%d",&n,&m); for(intI=1; i<=m;++i) scanf ("%d", &o[i]), + +O[i]; Sort (o+1, o+1+m); Memset (DP,0,sizeof(DP)); intC=m>1? o[2]:n+1; for(inti=o[1];i<c;++i) dp[i]=Val[i]; for(intI=2; i<=m;++i) for(intj=i<m?o[i+1]-1: n;j>=o[i];--j) for(intk=o[i-1];k<o[i];++k) Dp[j]=max (dp[j],dp[k]+val[j-K]); printf ("%d\n",(int) (Floor (dp[n]*1e6))); } return 0;}
View Code
HDU5653 Bomber man wants to bomb an Array simple DP