Bomber Man wants to bomb an Array.

题目连接:

http://acm.hdu.edu.cn/showproblem.php?pid=5653

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)).

Sample Input

2

10 2

0 9

10 3

0 4 8

Sample Output

4643856

5169925

Hint

题意

一个长为n的地方,有m个炸弹。

每个炸弹可以炸掉l+r+1的位置,表示这个炸弹炸掉左边l个,右边r个,自己所在的一个

然后他们炸完之后,的贡献就是a[1]*a[2]*....*a[n]

a[i]表示第i个炸掉了多少个

题解:

数据范围只有2000,所以直接暴力dp去枚举就好了

dp[i][j]表示考虑到第i个炸弹,炸到j的最大值

然后直接自信n^3瞎转移就好了

代码

#include<iostream>
#include<cmath>
#include<algorithm>
#include<stdio.h>
#include<cstring>
using namespace std;
const int maxn = 2005;
int n,m,a[maxn] ;
double dp[maxn][maxn]; int main()
{
int t;scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
memset(a,0,sizeof(a));
memset(dp,0,sizeof(dp));
for(int i=1;i<=m;i++)
scanf("%d",&a[i]),a[i]++;
sort(a+1,a+1+m);
a[++m]=n+2;
for(int i=1;i<=a[1];i++)
dp[1][i]=1;
for(int i = 2 ; i <= m ; ++ i){
for(int j = a[i-1]+1;j<=a[i];++j)
for(int k = a[i-2]+1 ; k <= a[i-1] ; ++ k )
dp[i][j]=max(dp[i][j],dp[i-1][k]*(j-k));
}
printf("%.0f\n",floor(1000000.0 * log2(dp[m][n+1])));
}
return 0;
}

HDU 5653 Bomber Man wants to bomb an Array. dp的更多相关文章

  1. hdu 5653 Bomber Man wants to bomb an Array

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5653 题意:已知炸弹可以炸掉左边L个位置,右边R个位置,那么炸点炸掉的总数是L+R+1.给定每个炸弹的 ...

  2. 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: 65 ...

  3. HDU5653 Bomber Man wants to bomb an Array 简单DP

    题意:bc 77 div1 1003(中文题面) 分析:先不考虑将结果乘以 1e6. 设 dp[i] 为从前 i 个格子的状态可以获得的最大破坏指数. 那么我们可以枚举每个炸弹,该炸弹向左延伸的距离和 ...

  4. HDOJ(HDU).4508 湫湫系列故事――减肥记I (DP 完全背包)

    HDOJ(HDU).4508 湫湫系列故事――减肥记I (DP 完全背包) 题意分析 裸完全背包 代码总览 #include <iostream> #include <cstdio& ...

  5. HDU 3555 Bomb(数位DP模板啊两种形式)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 Problem Description The counter-terrorists found ...

  6. HDU 3555 Bomb (数位DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 题目大意:从0开始到给定的数字N所有的数字中遇到“49”的数字的个数. Sample Input ...

  7. HDU 3555 Bomb(数位DP)

    Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Subm ...

  8. hdu 3555 Bomb ( 数位DP)

    Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Subm ...

  9. hdu 3555 Bomb 【数位DP】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 题意:上一题是不要62 这个是"不要49" 代码: #include < ...

随机推荐

  1. arch点击硬盘无法挂载

    出现问题如下 在使用xfce4桌面的时候在点击硬盘图标时可以挂载虽然要求你输入root密码 但是在使用openbox的时候点击硬盘图标却出现如下提示,权限的问题 Not authorized to p ...

  2. Perl6多线程3: Promise start / in / await

    创建一个Promise 并自动运行: my $p = Promise.start({say 'Hello, Promise!'}); 如果把代码改成如下, 我们会发现什么也没打印: ;say 'Hel ...

  3. python操作上级子文件

    . └── folder ├── data │ └── data.txt └── test1 └── test2 └── test.py import os '***获取当前目录***'print o ...

  4. Nginx实现404页面的几种方法【转】

    一个网站项目,肯定是避免不了404页面的,通常使用Nginx作为Web服务器时,有以下集中配置方式,一起来看看. 第一种:Nginx自己的错误页面 Nginx访问一个静态的html 页面,当这个页面没 ...

  5. C# 加密解密以及sha256不可逆加密案例

    class Program { static void Main(string[] args) { string aa = "身份证"; string bb = "key ...

  6. 122.Best Time to Buy and Sell Stock II---dp

    题目链接:https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/description/ 题目大意:基本定义与121类似,不 ...

  7. Maven如何发布项目到一个Tomcat中

    首先,在本地tomcat的conf/tomcat-users.xml 中配置一个user,准备让maven接入时使用: <role rolename="admin-gui"/ ...

  8. javadoc生成word接口文档

    1.下载DocFlex/Doclet 下载地址 http://www.filigris.com/downloads/ 2.ecplise->project->generate javado ...

  9. 让R与Python共舞

    转载:http://ices01.sinaapp.com/?p=129      R(又称R语言)是一款开源的跨平台的数值统计和数值图形化展现 工具.通俗点说,R是用来做统计和画图的.R拥有自己的脚本 ...

  10. 次短路经(dijsktra)

    #include <cstdio>#include <cstring>#include <queue>#include <algorithm>#defi ...