HDU 5653 Bomber Man wants to bomb an Array. DP

Posted Meek

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU 5653 Bomber Man wants to bomb an Array. DP相关的知识,希望对你有一定的参考价值。

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=X1X2....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(T20) 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;
}

 

以上是关于HDU 5653 Bomber Man wants to bomb an Array. DP的主要内容,如果未能解决你的问题,请参考以下文章

HDOJ 5653 Bomber Man wants to bomb an Array.(DP)

BestCoder Round #77 (div.2)(hdu5650,hdu5651(逆元),hdu5652(二分),hdu5653(dp))

dp hdu5653 xiaoxin and his watermelon candy

UVA10900 HDU1145 So you want to be a 2n-aire?概率期望

2016shenyang-1002-HDU5893-List wants to travel-树链剖分+线段树维护不同区间段个数

HDU 1495 非常可乐(数论,BFS)