CodeForces 1131G. Most Dangerous Shark
题目简述:从左到右依次有$n \leq 10^7$个Domino骨牌,高度为$h_i$,手动推倒他的花费为$c_i$。每个骨牌之间的距离为$1$。一个骨牌可以被向左或者向右推倒。当第$i$个骨牌被推倒时,他会以相同方向推倒与其距离$<h_i$的所有骨牌。求推倒所有骨牌的最小花费。
解:code
令$L[i], R[i]$分别表示第$i$个骨牌向左(右)推倒后,会将$(L[i], i]$($[i, R[i])$)区间内的骨牌推倒。这个可以用单调栈在$O(n)$时间内解决。
令$f[i]$表示(只通过推倒前$i$个骨牌来)推倒前$i$个骨牌的最小花费,则对$1 \leq i \leq n$,
$$ f[i] = \min\left\{ f[L[i]]+c_i, \min_{j < i < R[j]} \{f[j-1]+c_j\} \right\}, $$
这个动态规划也能用单调栈在$O(n)$时间内解决。
CodeForces 1131G. Most Dangerous Shark的更多相关文章
- 【CodeForces 621A】Wet Shark and Odd and Even
题 Today, Wet Shark is given n integers. Using any of these integers no more than once, Wet Shark wan ...
- 【CodeForces 621C】Wet Shark and Flowers
题 There are n sharks who grow flowers for Wet Shark. They are all sitting around the table, such tha ...
- 【38.24%】【codeforces 621E】 Wet Shark and Blocks
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- Codeforces1131G Most Dangerous Shark
Description Original Problem Chinese Translation 大概就是给你一个间隔为1的多米诺序列,推倒一个多米诺骨牌有个花费,求推倒所有多米诺骨牌的最小花费 So ...
- 【CodeForces 621B】Wet Shark and Bishops
题 题意 1000*1000的格子里,给你n≤200 000个点的坐标,求有多少对在一个对角线上. 分析 如果求每个点有几个共对角线的点,会超时. 考虑到对角线总共就主对角线1999条+副对角线199 ...
- Codeforces Gym101473 E.Dangerous Dive (2013-2014 ACM-ICPC Brazil Subregional Programming Contest)
代码: 1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<cmat ...
- Codeforces 1131G(dp)
传送门 与Codeforces1107G一起食用 思路 想到要用dp--然后常规地设dp[i]为推倒前i个牌的最小花费 有两种情况:一是当前这个推,二是不推而被别人推.对于第一种,需要找到这个左推(因 ...
- Codeforces Round #541 (Div. 2) (A~F)
目录 Codeforces 1131 A.Sea Battle B.Draw! C.Birthday D.Gourmet choice(拓扑排序) E.String Multiplication(思路 ...
- Codeforces 1131 (div 2)
链接:http://codeforces.com/contest/1131 A Sea Battle 利用良心出题人给出的图,不难看出答案为\(2*(h1+h2)+2*max(w1,w2)+4\)由于 ...
随机推荐
- 查询SQL2008字段和注释
SELECT 表名 then d.name else '' end, 表说明 then isnull(f.value,'') else '' end, 字段序号 = a.colorder, 字段名 = ...
- Python 爬虫常见的坑和解决方法
1.请求时出现HTTP Error 403: Forbidden headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23. ...
- Android-Android进程间通讯之messenger
转自‘https://www.cnblogs.com/makaruila/p/4869912.html 平时一说进程间通讯,大家都会想到AIDL,其实messenger和AIDL作用一样,都可以进行进 ...
- MySQL 忘记密码解决办法
第一步: 关闭MySQL服务. 第二步: 打开DOS窗口,在里面输入安装MqSQL的目录本机为:C:\Program Files\MySQL\MySQL Server 5.6\bin 第三步: 在命 ...
- python推荐系统库
Python推荐系统库——Surprise 在Python中实现你自己的推荐系统 python-recsys:一款实现推荐系统的python库
- Refused to set unsafe header
Refused to set unsafe header Refused to set unsafe header "Host"waitServerDeal @ tGet.html ...
- quick-cocos2d-x 系列之——环境搭建(Mac版)
quick-cocos2d-x简单介绍 何为quick-cocos2d-x? ? 简单一句话:quick-cocos2d-x是採用lua语言,通过tolua++工具对cocos2d-x进一步封装, ...
- JETSON TK1~Ubuntu14.04 Armhf源更新
Ubuntu armhf版本的源网址不同于普通Ubuntu系统,如果采用如下网址会出现问题,导致sudo apt-get update出现Error. 之前的连接: deb http://archiv ...
- iOS审核总被拒?腾讯教你提升iOS审核通过率!
作者:Jamie,腾讯开发工程师,在iOS预审和ASO优化领域从事专项测试相关工作,为腾讯游戏近100个产品提供专项服务. 商业转载请联系腾讯WeTest获得授权,非商业转载请注明出处. WeTest ...
- nodejs socket.io初探
1.安装socket.io npm install socket.io 2.创建服务端代码server.js var app = require('http').createServer(handle ...