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=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;
}
时间: 2024-10-11 00:48:28

HDU 5653 Bomber Man wants to bomb an Array. DP的相关文章

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

[HDOJ 5653] Bomber Man wants to bomb an Array.(DP) Bomber Man wants to bomb an Array. Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 389    Accepted Submission(s): 117 Problem Description Give

HDU5653 Bomber Man wants to bomb an Array 简单DP

题意:bc 77 div1 1003(中文题面) 分析:先不考虑将结果乘以 1e6. 设 dp[i] 为从前 i 个格子的状态可以获得的最大破坏指数. 那么我们可以枚举每个炸弹,该炸弹向左延伸的距离和向又延伸的距离. 设第 i 个炸弹破坏区间为 [l, r], 则 dp[r] = dp[l - 1] + log2(r - l + 1).答案就是 dp[n - 1].不要忘记最后要向下取整. 注:我对官方题解稍作解释,dp[i]代表前i个格子可以获得的最大破坏指数 但是更新的时候,需要注意,假设有

hdu 3555 Bomb(数位dp)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 题目大意:就是给你一个数n,判断从0到n有多少个数含有数字49...... 是不是觉得跟hdu2089很相似呀... 思路:跟hdu2089一样的,注意给出的数比较大,所以这儿用__int64  .... code: #include<cstdio> #include<iostream> #include<cstring> #include<algorithm&

HDU - 3555 Bomb (数位DP)

题意:求1-n里有多少人包含"49"的数字 思路:数位DP,分三种情况:到第i位没有49的情况,到第i位没有49且最高位是9的情况,到第i位有49的情况,将三种情况都考虑进去就是了 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; long long dp[30][3], n; int arr

HDU 4122 Alice&#39;s mooncake shop 单调队列优化dp

Alice's mooncake shop Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4122 Description The Mid-Autumn Festival, also known as the Moon Festival or Zhongqiu Festival is a popular harvest festival celebrated by Ch

hdu 3006 The Number of set(思维+壮压DP)

The Number of set Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1056    Accepted Submission(s): 655 Problem Description Given you n sets.All positive integers in sets are not less than 1 and

HDU 1565 方格取数(1) (状态压缩DP)

HDU 1565 方格取数(1) (状态压缩DP) ACM 题目地址: HDU 1565 方格取数(1) 题意: 中文. 分析: dp[i][j]表示前i行状态j的最优解. 先预处理出符合条件的数,17000+个(n在20以内). 不过感觉复杂度挺高的会T,但是却能A. 这题的正解应该是最小割,回头补下. 代码: /* * Author: illuz <iilluzen[at]gmail.com> * File: 1565_dp.cpp * Create Date: 2014-09-19 23

hdu 5135 Little Zu Chongzhi&#39;s Triangles 状压DP

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5135 从大到小贪心是不对的! 比如 4 30 40 50 89 这组数据 结果应该是600 如果取后三条边只会是一个细长细长的三角形根本没多大面积 只不过因为数据水然后贪心碰巧能过而已 看到网上题解很多人用贪心我好郁闷... 状压DP 看到边的数目很少就应该想到这个了 先枚举可能出现的所有三角形 记录他们使用了那些边还有他们的面积 然后再枚举状态之中 套一层遍历所有三角形的循环 如果当前状态和三角形

hdu 3030 Increasing Speed Limits (离散化+树状数组+DP思想)

Increasing Speed Limits Time Limit: 2000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 481    Accepted Submission(s): 245 Problem Description You were driving along a highway when you got caught by the road p