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 ...
随机推荐
- BZOJ3172——[Tjoi2013]单词
1. 题目大意:一篇论文是由许多单词组成,现在想知道每个单词分别在论文中出现多少次. 2.分析:对着 广义后缀自动机的图看,我们就会发现玄机,答案不就是这个单词下的后缀个数吗? 于是建立自动机,然后求 ...
- BZOJ 1044: [HAOI2008]木棍分割
Description 求 \(n\) 根木棍长度为 \(L\) ,分成 \(m\) 份,使最长长度最短,并求出方案数. Sol 二分+DP. 二分很简单啊,然后就是方案数的求法. 状态就是 \(f[ ...
- BZOJ 1419: Red is good
Sol 期望DP. \(f[i][j]\) 表示剩下 \(i\) 张红牌, \(j\) 张黑牌的期望. 有转移方程. \(f[i][j]=0,i=0\) 没有红色牌了,最优方案就是不再翻了. \(f[ ...
- Ubuntu14.04安装intel集显驱动
Ubuntu14.04安装intel集显驱动 标签(空格分隔): ubuntu linux 驱动安装 1.查看本机显卡型号 使用lspci命令来获取PCI接口硬件信息 o@o-pc:~$ lspci ...
- 11.6---矩阵查找元素(CC150)
思路,一旦提到查找就要想到二分查找. public static int[] findElement(int[][] a, int n, int m, int key) { // write code ...
- 2.2---找链表倒数第K个结点
答案,注意,一种是递归,另一种是迭代,那么巧妙利用双指针: 迭代: public static LinkedListNode nthToLast(LinkedListNode head, int n) ...
- WIN7 IIS7 安装方法
一.首先是安装IIS.打开控制面板,找到"程序与功能",点进去. 二.点击左侧"打开或关闭Windows功能". 三 看下图打相应的钩.
- Java读取mat文件
概述 使用ujmp中的jmatio模块读取.mat文件到java程序中. 其实,ujmp主要是在模块core中实现了矩阵运算,其余模块都是复用了已有的开源库.模块jmatio是复用了已有的JMatIo ...
- C++中string,wstring,CString的基本概念和用法
一.概念 string和CString均是字符串模板类,string为标准模板类(STL)定义的字符串类,已经纳入C++标准之中.wstring是操作宽字符串的类.C++标准程序库对于string的设 ...
- jQuery修改页面元素的属性
作为一个后台开发者,在web开发的时候会常常遇到修改前台页面的属性的问题.这两天我发现jQuery的$("#id").attr("prop","值&q ...