hdu-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): 382    Accepted Submission(s): 114


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
 
题意:
 
xi为第i个炸弹炸的格子的数目,问x1*x2*..xm的最大值是多少;
 
 
思路:
 
比赛的时候直接没怎么想这题,后来看别人博客说是dp,然后发现是一个区间dp,在两个相邻格子的中间选取这两个炸弹的分界点,找到使ans最大的点;还有就是函数库里面没有log2的函数,可以用换底公式log2(n)=log10(n)/log(2);
 
 
AC代码:
 
/*
Problem : 5653 ( Bomber Man wants to bomb an Array. )     Judge Status : Accepted
RunId : 16703569    Language : G++    Author : 2014300227
*/
#include <bits/stdc++.h>
using namespace std;
int n,m,a[2004];
double dp[2002][2002];
const double N=1000000;
int main()
{
   int t;
   scanf("%d",&t);
   while(t--)
   {
       scanf("%d%d",&n,&m);
       for(int i=0;i<=m;i++)
           for(int j=0;j<=n;j++)
            dp[i][j]=0;
        for(int i=1;i<=m;i++)
        {
            scanf("%d",&a[i]);
            a[i]++;
        }
        a[0]=0;
        a[m+1]=n+1;
        sort(a,a+m+2);
        for(int i=1;i<a[2];i++)
        {
            dp[1][i]=log10(i*1.0)/log10(2.0)*N;
        }
        for(int i=2;i<=m;i++)
        {
            for(int j=a[i];j<a[i+1];j++)
            {
                for(int k=a[i-1];k<a[i];k++)
                {
                    dp[i][j]=max(dp[i][j],dp[i-1][k]+log10((j-k)*1.0)/log10(2)*N);
                }
            }
        }
       int ans=(int)(dp[m][n]);
       printf("%d\n",ans);
   }

    return 0;
}

 

 

转载于:https://www.cnblogs.com/zhangchengc919/p/5330261.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值