hdu 5653 Bomber Man wants to bomb an Array
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5653
题意:已知炸弹可以炸掉左边L个位置,右边R个位置,那么炸点炸掉的总数是L+R+1。给定每个炸弹的位置,求所有炸弹炸掉的格数总乘积
输出floor(1e6*log2(总乘积))那么到计算时就变成先取对数相加,最后乘以1e6下取整
思路:dp[r]=dp[l-1]*log2(r-l+1)当前区间的最大值等于上一个区间的最大值加上当前的值,解释见代码
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<vector>
#include<queue>
#include<map>
#include<iterator>
#include<vector>
#include<set>
#define INF 9999999
typedef long long ll;
const int Max=(<<)+;
using namespace std; double dp[];
int num,n,m,b[]; int main()
{
scanf("%d",&num);
while(num--)
{
scanf("%d %d",&n,&m);
for(int i=;i<=m;i++)
{
scanf("%d",&b[i]);
b[i]++;
} sort(b+,b+m+); b[m+]=n+;
memset(dp,,sizeof(dp)); for(int i=;i<=m;i++)
{
for(int j=b[i-]+;j<=b[i];j++)
{
for(int k=b[i];k<=b[i+]-;k++)
dp[k]=max(dp[k],dp[j-]+log2(k-j+1.0));//枚举区间求最大值,j表示当前区间的起点,k表示当前区间的终点,j-1表示上一个区间
}
}
ll ans=floor(1e6*dp[n]);
printf("%lld\n",ans);
}
return ;
}
hdu 5653 Bomber Man wants to bomb an Array的更多相关文章
- 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 ...
- 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 个格子的状态可以获得的最大破坏指数. 那么我们可以枚举每个炸弹,该炸弹向左延伸的距离和 ...
- BestCoder Round #77
T1 xiaoxin juju needs help 计算组合数然后多重集排列乱搞,注意判无解情况(TM我就判错然后FST了). #include<cstdio> #include< ...
- HDU 5164Matching on Array(AC自动机)
这是BC上的一道题,当时比赛没有做,回头看看题解,说是AC自动机,想着没有写过AC自动机,于是便试着抄抄白书的模板,硬是搞了我数个小时2000ms时限1800过了= = ! 这里就直接贴上BC的结题报 ...
- hdu 5635 LCP Array(BC第一题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5635 LCP Array Time Limit: 4000/2000 MS (Java/Others) ...
- 2017 多校2 hdu 6053 TrickGCD
2017 多校2 hdu 6053 TrickGCD 题目: You are given an array \(A\) , and Zhu wants to know there are how ma ...
- hud 3336 count the string (KMP)
这道题本来想对了,可是因为hdu对pascal语言的限制是我认为自己想错了,结果一看题解发现自己对了…… 题意:给以字符串 计算出以前i个字符为前缀的字符中 在主串中出现的次数和 如: num(aba ...
- HDU 5934 Bomb(炸弹)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
随机推荐
- BZOJ4196——noi2015软件包管理器
1.题目大意:讲道理,就是让你有两个修改一个是把一个点到根的路径上的点权值全部变成1,另一个是把一个子树全部变成0 然后让你输出每次修改,改变的哪些节点的值 2.分析:就是一个树剖,树剖是满足dfs序 ...
- BZOJ1012——[JSOI2008]最大数maxnumber
1.题目大意:求末尾L个数的最大值,强制在线 2.分析:这个拿线段树可以直接水过,然后我写了一个 维护单调栈, 二分求最大值的短代码,手懒.... #include <cstdio> #i ...
- leetcode 86. Partition List
Given a linked list and a value x, partition it such that all nodes less than x come before nodes gr ...
- LAMP环境的安装
感觉一下子喜欢上了ubuntu.界面特别舒服.打算物理机装ubuntu了都. 00x1 LINUX linux我安装过了就不演示了,百度经验的一篇文章:http://jingyan.baidu.com ...
- zipimport.ZipImportError: can't decompress data; zlib not available 解决办法
第一步,下载python-pip的tar包 # wget https://pypi.python.org/packages/source/p/pip/pip-1.3.1.tar.gz --no-che ...
- 11.5---含有空字符串的字符串查找(CC150)
注意,1,"" 和 " ".是不同的,空字符串指的是"": 2,注意String的compareTo.小于是指<0.并不是==-1: ...
- 开源中国git使用方法
1.添加公匙. 打开开源中国git公匙管理 用TortoiseGit Puttygen生成公匙文件 生成过程中 不断移动点击鼠标(因为生成密匙过程是记录鼠标变化作为加密过程) ...
- 【Networking】Thrift and gRPC
参考资料: http://doc.oschina.net/grpc?t=60138 http://www.grpc.io/ https://thrift.apache.org/ https://git ...
- 【GoLang】GO语言系列--002.GO语言基础
002.GO语言基础 1 参考资料 1.1 http://www.cnblogs.com/vimsk/archive/2012/11/03/2736179.html 1.2 https://githu ...
- ADO.NET和ADO.NET Entity Framework
ADO.NET 3.0 用于访问和操作数据的两个主要组件是 .NET Framework 数据提供程序和 DataSet. .NET Framework 数据提供程序 .NET Framework 数 ...