HDU 5653 Bomber Man wants to bomb an Array. dp
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
- Bomber Man wants to plant a bomb at every bombing location.
- Bomber Man wants to destroy each block with only once.
- 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的更多相关文章
- hdu 5653 Bomber Man wants to bomb an Array
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5653 题意:已知炸弹可以炸掉左边L个位置,右边R个位置,那么炸点炸掉的总数是L+R+1.给定每个炸弹的 ...
- 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 ...
- HDU5653 Bomber Man wants to bomb an Array 简单DP
题意:bc 77 div1 1003(中文题面) 分析:先不考虑将结果乘以 1e6. 设 dp[i] 为从前 i 个格子的状态可以获得的最大破坏指数. 那么我们可以枚举每个炸弹,该炸弹向左延伸的距离和 ...
- HDOJ(HDU).4508 湫湫系列故事――减肥记I (DP 完全背包)
HDOJ(HDU).4508 湫湫系列故事――减肥记I (DP 完全背包) 题意分析 裸完全背包 代码总览 #include <iostream> #include <cstdio& ...
- HDU 3555 Bomb(数位DP模板啊两种形式)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 Problem Description The counter-terrorists found ...
- HDU 3555 Bomb (数位DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 题目大意:从0开始到给定的数字N所有的数字中遇到“49”的数字的个数. Sample Input ...
- HDU 3555 Bomb(数位DP)
Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Subm ...
- hdu 3555 Bomb ( 数位DP)
Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Subm ...
- hdu 3555 Bomb 【数位DP】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 题意:上一题是不要62 这个是"不要49" 代码: #include < ...
随机推荐
- AngularJS 指令绑定 & 简介
指令中独立scope 的 & 官方说明: 1. 绑定表达式 2. 经常用来绑定回调函数 诡异的地方在于,这个 & 某次听人说在子组件中是不能传值给callback的,好奇查了一下官方文 ...
- python自动开发之(算法)第二十七天
1.什么是算法? 算法(Algorithm):一个计算过程,解决问题的方法 2.复习:递归 递归的两个特点:(1) 调用自身 (2)结束条件 def func1(x): print(x) func1( ...
- 191.Number of 1Bits---位运算---《剑指offer》10
题目链接:https://leetcode.com/problems/number-of-1-bits/description/ 题目大意:与338题类似,求解某个无符号32位整数的二进制表示的1的个 ...
- FusionCharts 用法心得
现在主流的很多jQuery+js结合的图表展示插件,有HighCharts,ECharts等等,今天我们先来了解一下FusionCharts,也是一个非常不错的图表制作工具.希望我的同事以及其他需要帮 ...
- php 学习try_catch测试抛出异常
/** * Class show * 一个catch接收抛出异常 */ class show { // 错误的演示 //try { //require ('test_try_catch.php'); ...
- linux nginx php-fpm被攻击
1.nginx错误日志:报错 2018/05/30 16:30:55 [error] 8765#0: *1485 connect() to unix:/tmp/php-70-cgi.sock fail ...
- C# 解决窗体闪烁
C# 解决窗体闪烁 在Windows窗体上造成“闪烁”的窗体上有很多控制.造成这种闪烁的原因有两个: 1.当控件需要被绘制时,Windows发送一个控件两个消息.第一个(WM_ERASEBKGND)导 ...
- break、continue多层循环处理
使用break xxx跳出多层循环的代码如下: for(String s: arr){ labelA: for(String ss: arr) { for(String sss: arr) { Sys ...
- 【58沈剑架构系列】DB主从一致性架构优化4种方法
需求缘起 大部分互联网的业务都是“读多写少”的场景,数据库层面,读性能往往成为瓶颈.如下图:业界通常采用“一主多从,读写分离,冗余多个读库”的数据库架构来提升数据库的读性能. 这种架构的一个潜在缺点是 ...
- C# 6.0 新特性 (四)
原文: 1.http://www.cnblogs.com/BoyceYang/p/3711343.html 2.http://www.cnblogs.com/lhking/p/3660182.html ...