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\)由于 ...
随机推荐
- WCF配置心得
根据蒋金楠老师的博文所说的, WCF的终结点有三个要素组成,分别是地址(Address).绑定(Binding)和契约(Contract),简记可写成Endpoint = ABC. 地址:地址决定了服 ...
- C#使用for循环移除HTML标记
public static string StripTagsCharArray(string source) { char[] array = new char[source.Length]; int ...
- mongodb.py
from chatterbot.storage import StorageAdapter class Query(object): def __init__(self, query={}): sel ...
- myeclipse中disable maven nature怎么恢复
eclipse更新maven的时候,不小心手一抖,点上了Disable Maven Nature,然后工程右键菜单中的Maven栏就不见了! 其实这是把maven工程转换成了一般工程,再转回来就好了. ...
- ES中DSL查询相关
elasticsearch中的API:http://www.cnblogs.com/yjf512/p/4862992.html elasticsearch查询系列:http://blog.csdn.n ...
- Magnetic Fingerprinting Approach to Indoor Localization
Magnetic Fingerprinting Approach to Indoor Localization
- AndroidUI组件之ImageSwitcher
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/gc_gongchao/article/details/25594669 今天继续AndroidUI组 ...
- Java AQS详解(转)
原文地址 一.概述 谈到并发,不得不谈ReentrantLock:而谈到ReentrantLock,不得不谈AbstractQueuedSynchronizer(AQS)! 类如其名,抽象的队列式的同 ...
- python连接redis并插入url
#!/usr/bin/env python # -*- coding:utf8 -*- import redis ''' 这种连接是连接一次就断了,耗资源.端口默认6379,就不用写 r = redi ...
- IOS 状态栏 显示与隐藏网络活动状态
IOS中显示和隐藏状态栏的网络活动标志 //在向服务端发送请求状态栏显示网络活动标志: [[UIApplication sharedApplication] setNetworkActivityInd ...