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 ...
随机推荐
- outlet删除不完全
今天在用iOS写个计算器的时候,遇到的一个小bug,新手,太新了,不之所错. 直接上码: Terminating app due to uncaught exception 'NSUnknownKey ...
- jxl和poi处理excel之比较
功能需求是根据客户提供的excel模板,程序动态填充其中的一些数据.该模板包含大量的宏,刚拿到的时候头都要晕了,本人虽天天和电脑打交道,但是excel咱不是高手啊,什么宏,之前光听过,听着都觉得是高级 ...
- 正确理解javascript的this关键字
javascript有this关键字,它和javascript的执行上下文有着密切的关系,就是说this具体指代什么要根据它的上下文来判断. 一.this和对象的关系 var Person={ ...
- jquery改变多个css样式
<!DOCTYPE html> <html> <head> <script src="http://ajax.googleapis.com/ajax ...
- Cassandra1.2文档学习(5)—— Snitch
参考资料:http://www.datastax.com/documentation/cassandra/1.2/webhelp/index.html#cassandra/architecture/a ...
- Windows系统下Oracle数据库冷备
一.背景: 具体的场景是数据库不是普通的OLTP系统,更像是OLAP系统,数据的更新频率很低,在noarchivelog 模式下运行,实时性要求低,但是数据只有一份不能弄丢,需要应付磁盘损坏等情况.这 ...
- SanDisk SecureAccess™ Software
买了一个sandisk 的u盘,配套软件有空可以研究一下. QuickStartGuide_SanDiskSecureAccessV2.0.pdf http://www.sandisk.com/pro ...
- Spring 数据源配置二:多数据源
通过上一节 Spring 数据源配置一: 单一数据源 我们了解单一数据源的配置, 这里我们继续多个数据源的配置 如下(applicationContent.xml 内容) 一: Spring ...
- jquery怎么实现左右滑动的问题
var len = $("#b span").length, curindex = 0; $("#leftRun").click(function(){ if( ...
- Error -27791: Server xx has shut down the connection prematurely
最近在进行一次性能测试中遇到一个问题,并发较大的时候会出现LR出现Error -27791: Server xx has shut down the connection prematurely的ER ...