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 ...
随机推荐
- linux修改时间 时区
查看时区:date -R 修改时区 cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 二.时间 1.查看时间和日期 date 2.设置时间和日期 ...
- java感触一则
看到开源中国上边有那么多关于java的开源项目,从数据库到3D游戏再到IDE工具,甚至有iQQ,形形种种都是一些比较成熟的,工程很大的项目.才意识到Java是如此的强大和流行. 这么多开源的代码我不可 ...
- [HTML]marquee标签属性详解
请大家先看下面这段代码:<marquee direction=upbehavior=scrollloop=3scrollamount=1 scrolldelay=10align=topbgcol ...
- django 的请求处理部分----WSGIHandler 源码分析 django1.5.5
从这里拉开django框架的帷幕..撕开,哈哈 主要涉及的类:django.core.handlers.base.BaseHandler,django.core.handlers.wsgi.WSGIH ...
- vim file save as
the command of vim to save as the file :w new_file_name
- linux下i2c驱动笔记 转
1. 几个基本概念 1.1. 设备模型 由 总线(bus_type) + 设备(device) + 驱动(device_driver) 组成,在该模型下,所有的设备通过总线连接起来,即使有些设备没有连 ...
- POJ 3254 压缩状态DP
题意:一个矩形网格,可以填0或1, 但有些位置什么数都不能填,要求相邻两个不同时为1,有多少种填法.矩形大小最大 12*12. 压缩状态DP大多有一个可行的state的范围,先求出这个state范围, ...
- 仿今日头条最强顶部导航指示器,支持6种模式-b
项目中经常会用到类似今日头条中顶部的导航指示器,我也经常用一个类似的库PagerSlidingTabStrip,但是有时并不能小伙伴们的所有需求,所以我在这个类的基础上就所有能用到的情况做了一个简单的 ...
- 17款code review工具
本文是码农网原创翻译,转载请看清文末的转载要求,谢谢合作! 好的代码审查器可以大大地帮助程序员提高代码质量,减少错误几率. 虽然现在市场上有许多可用的代码审查工具,但如何挑选也是一个艰巨的任务.在咨询 ...
- 在MAC中安装Compass的方法 (转)
在MAC中通过gem命令安装compass时会出异常,原因是compass版本更新了,一些运行时所用到的依赖软件的版本没能得到更新,故而出现错误.例如,用以下命令安装compass: $ gem in ...