HDU 5653 (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): 143    Accepted Submission(s): 43


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  i th 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  i th 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
 


题意:一个炸弹能够炸掉包括自己的一个连续区间内的格子,一个炸弹的威力用它炸掉的区间长度表示.n个

格子中给出m个炸弹的位置,求所有炸弹的威力之积的最大值.

由于题目要求输出的威力之积的对数,可以用乘积的对数转化为对数的和来减少精度误差.假设DP[i]表示i之

间炸完的最大价值对数和,那么DP[i] = max (DP[j]+log(j-i)/log(2)),能够转移的前提是区间[i,j-1]之间恰好存

在一个炸弹.

#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
using namespace std;
#define maxn 2111

double dp[maxn];//dp[i]表示i之前炸完的最大价值
int n, m;
int pos[maxn], sum[maxn];

double f (int x) {
    double ans = log (1.0*x)/log (2);
    return ans;
}

int main () {
    //freopen ("in.txt", "r", stdin);
    int t;
    scanf ("%d", &t);
    while (t--) {
        memset (sum, 0, sizeof sum);
        scanf ("%d%d", &n, &m);
        for (int i = 1; i <= m; i++) {
            int x;
            scanf ("%d", &x);
            sum[x+1] = 1;
        }
        for (int i = 1; i <= n; i++) sum[i] = sum[i-1]+sum[i];
        memset (dp, 0, sizeof dp);
        for (int i = 1; i <= n+1; i++) {
            for (int j = 1; j < i; j++)
                if (sum[i-1]-sum[j-1] == 1)
                    dp[i] = max (dp[i], dp[j]+f (i-j));
        }
        printf ("%lld\n", (long long)((floor)(1000000.0*dp[n+1])));
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值