Bomber Man wants to bomb an Array.
Problem Description
Given an array and some positions where to plant the bombs, You have to print the Total Maximum Impact.
Each Bomb has some left destruction capability L and some right destruction capability R which means if a bomb is dropped at ith location it will destroy L blocks on the left and R blocks on the right.
Number of Blocks destroyed by a bomb is L+R+1
Total Impact is calculated as product of number of blocks destroyed by each bomb.
If ith bomb destroys Xi blocks then TotalImpact=X1∗X2∗....Xm
Given the bombing locations in the array, print the Maximum Total Impact such that every block of the array is destoryed exactly once(i.e it is effected by only one bomb).
### Rules of Bombing
1. Bomber Man wants to plant a bomb at every bombing location.
2. Bomber Man wants to destroy each block with only once.
3. Bomber Man wants to destroy every block.
Input
There are multi test cases denote by a integer T(T≤20) in the first line.
First line two Integers N and M which are the number of locations and number of bombing locations respectivly.
Second line contains M distinct integers specifying the Bombing Locations.
1 <= N <= 2000
1 <= M <= N
Output
as Maximum Total Impact can be very large print the floor(1000000 * log2(Maximum Total Impact)).
Hint:
Sample 1:
Sample 2:
Sample Input
2
10 2
0 9
10 3
0 4 8
Sample Output
4643856
5169925
题意:
给一个长度为 NN 的一维格子和一些炸弹的位置,请你计算 “最大总破坏指数”。 每个炸弹都有向左和向右的破坏力,如果一个炸弹向左和向右的破坏力分别为 LL 和 RR, 那么该炸弹将炸毁 L + R + 1L+R+1 个格子(左边LL个,炸弹所在格子,右边RR个)。 破坏指数的计算方式为:所有炸弹炸毁的格子数的乘积。假设第 ii 个炸弹炸毁了 X_iX?i??个格子, 那么总破坏指数就是 X_1 * X_2 * .... X_mX?1??∗X?2??∗....X?m??。 现在告诉你每个炸弹的位置,你需要计算 最大的总破坏指数,注意:每个格子最多只允许被炸一次。
题解:
DP
设定f[i][j] 表示前i个炸弹到j的最大破坏力
我们在得知f[i][k]下 枚举当前炸弹左右范围更新答案就好了
#pragma comment(linker, "/STACK:10240000,10240000") #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> #include<iostream> const int N = 2e3+10 , M = 1e6+20; using namespace std; typedef long long ll; int T,n,m; double f[N][N]; int a[N],x; int main() { scanf("%d",&T); while(T--) { scanf("%d%d",&m,&n); for(int i=1;i<=n;i++) scanf("%d",&x), a[i] = x + 1; sort(a+1,a+n+1); memset(f,0,sizeof(f)); f[0][0] = 0.0; a[0] = 0, a[n+1] = m+1; for(int i=1;i<=n;i++) { for(int j=a[i];j<a[i+1];j++) { for(int k=a[i-1]+1;k<=a[i];k++) { f[i][j] = max(f[i][j], f[i-1][k-1] + log(j-k+1)/ log(2)); } } } printf("%lld\n",(ll)floor(1000000*f[n][m])); } return 0; }