HDU5653 Bomber Man wants to bomb an Array 简单DP
题意:bc 77 div1 1003(中文题面)
分析:先不考虑将结果乘以 1e6。 设 dp[i] 为从前 i 个格子的状态可以获得的最大破坏指数。
那么我们可以枚举每个炸弹,该炸弹向左延伸的距离和向又延伸的距离。
设第 i 个炸弹破坏区间为 [l, r], 则 dp[r] = dp[l - 1] + log2(r - l + 1)。答案就是 dp[n - 1]。不要忘记最后要向下取整。
注:我对官方题解稍作解释,dp[i]代表前i个格子可以获得的最大破坏指数
但是更新的时候,需要注意,假设有 n 个炸弹,第 i 个炸弹的位置是o[i]
那么考虑处理到第i个炸弹,他能更新的dp[j]是有限制的,o[i]<=j<o[i+1],因为一个炸弹的爆炸区域不可能跨过另外一个炸弹
更新dp[j]的也dp[k]也是有限制的,o[i-1]<=k<=o[i],道理是一样的
然后看起来是三重循环,实际上很小
然后有一个小优化,事先把log2(1-2000)打出来,因为这个函数很慢
#include<cstdio>
#include<cstring>
#include<queue>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
typedef long long LL;
const int N=2e3+;
const int INF=0x3f3f3f3f;
int o[N];
double dp[N],val[N];
int main(){
for(int i=;i<=;++i)
val[i]=log(i)/log();
int T;
scanf("%d",&T);
while(T--){
int n,m;
scanf("%d%d",&n,&m);
for(int i=;i<=m;++i)
scanf("%d",&o[i]),++o[i];
sort(o+,o++m);
memset(dp,,sizeof(dp));
int c=m>?o[]:n+;
for(int i=o[];i<c;++i)
dp[i]=val[i];
for(int i=;i<=m;++i)
for(int j=i<m?o[i+]-:n;j>=o[i];--j)
for(int k=o[i-];k<o[i];++k)
dp[j]=max(dp[j],dp[k]+val[j-k]);
printf("%d\n",(int)(floor(dp[n]*1e6)));
}
return ;
}
HDU5653 Bomber Man wants to bomb an Array 简单DP的更多相关文章
- 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 ...
- 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
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5653 题意:已知炸弹可以炸掉左边L个位置,右边R个位置,那么炸点炸掉的总数是L+R+1.给定每个炸弹的 ...
- HDU5280 Senior's Array(简单DP)
题目链接:pid=5280">传送门 题意: 给定一个长度为n的序列,和一个改动的值p,必须从原序列中选一个位置改动成p, 求改动后的区间和的最大值. 分析: 枚举位置+最大区间和. ...
- Educational Codeforces Round 63 (Rated for Div. 2) D. Beautiful Array (简单DP)
题目:https://codeforces.com/contest/1155/problem/D 题意:给你n,x,一个n个数的序列,你可以选择一段区间,区间的数都乘以x,然后求出最大字段和 思路: ...
- AIM Tech Round (Div. 2) D. Array GCD dp
D. Array GCD 题目连接: http://codeforces.com/contest/624/problem/D Description You are given array ai of ...
- C#:System.Array简单使用
1.C# 中的数组 1.1 定义数组: 1.1.1 定义不初始化:数据类型[] 数组名称= new 数据类型[元素个数]; 1.1.2 定义并初始化:数据类型[] 数组名称= new 数据类型[ ...
- C. Ayoub and Lost Array cf dp
C. Ayoub and Lost Array time limit per test 1 second memory limit per test 256 megabytes input stand ...
- 121. Best Time to Buy and Sell Stock (Array;DP)
Say you have an array for which the ith element is the price of a given stock on day i. If you were ...
随机推荐
- vsftpd.conf配置详解
根据 /etc/vsftpd/vsftpd.conf默认配置给出设定功能 # Example config file /etc/vsftpd/vsftpd.conf # The default c ...
- python 调用第三方库压缩png或者转换成webp
因为工作需要去研究了下png的压缩,发现转换成webp可以小很多,但是webp在手机上的解码速度比png的解码速度慢很多.出于进几年手机设备的处理器的性能也不错了,所以准备两套方案. 在网上搜索了一些 ...
- Windows系统下Oracle数据库冷备
一.背景: 具体的场景是数据库不是普通的OLTP系统,更像是OLAP系统,数据的更新频率很低,在noarchivelog 模式下运行,实时性要求低,但是数据只有一份不能弄丢,需要应付磁盘损坏等情况.这 ...
- MVC去掉传参时的验证:从客户端中检测到有潜在危险的Request.QueryString值
解决方法:给Action添加属性[ValidateInput(false)]. 例: [ValidateInput(false)] public ActionResult Index(string o ...
- 一步步学习NHibernate(2)——配置NHibernate的环境
请注明转载地址:http://www.cnblogs.com/arhat 第二章 环境搭建 在上一章中,我们知道了NHibernate是用来干什么的了,那么今天在本章中,我们开始搭建NHibernat ...
- MongoDB索引介绍
MongoDB中的索引其实类似于关系型数据库,都是为了提高查询和排序的效率的,并且实现原理也基本一致.由于集合中的键(字段)可以是普通数据类型,也可以是子文档.MongoDB可以在各种类型的键上创建索 ...
- mongodb MongoDB 聚合 group
MongoDB 聚合 MongoDB中聚合(aggregate)主要用于处理数据(诸如统计平均值,求和等),并返回计算后的数据结果.有点类似sql语句中的 count(*). 基本语法为:db.col ...
- Automotive Security的一些资料和心得(4):Automotive Safeguards
通常一辆汽车会包括超过80个ECUs.所有软件代码大小正在快速增加,将会超过1GB.软件protection是必不可少的. 1. 软件保护 1.1. 安全boot Software violating ...
- bzoj 3105: [cqoi2013]新Nim游戏 异或高消 && 拟阵
3105: [cqoi2013]新Nim游戏 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 535 Solved: 317[Submit][Stat ...
- 【深度学习系列3】 Mariana CNN并行框架与图像识别
[深度学习系列3] Mariana CNN并行框架与图像识别 本文是腾讯深度学习系列文章的第三篇,聚焦于腾讯深度学习平台Mariana中深度卷积神经网络Deep CNNs的多GPU模型并行和数据并行框 ...