首页 > 其他分享 >UVA 12170

UVA 12170

时间:2023-08-02 11:45:27浏览次数:36  
标签:le min cdot Step 12170 answer UVA dp

从另一个网站上的我的博客里转的。感觉放在一起比较好。时间久远,而且是英文(流泪)。

Easy Climb

Step 1

If \(x_i,d\le 100\).

Then define \(dp_{i,j}\) as the minimum cost for the first \(i\) stacks, with \(j\) as the height of the \(i^{\tt{th}}\) stack.

Then, the formula is very simple.

  • \(dp_{i,j}=\displaystyle\min_{k=\max\{0,j-d\}}^{\min\{300,j+d\}}\{dp_{i-1,k}\}\)

But the time complexity is \(O(n^2d)\), so it will TLE.


Step 2

Observation 1

Define \(h_i'\) as the final value of the height of stack \(i\).

Then, \(h_i'\in\{h_{j \ (1\le j \le n)}+x (-n\le x\le n)\cdot d\}\).

Proof for Obervation 1

Consider the case when \(h_i'\notin\{h_{j \ (1\le j \le n)}+x (-n\le x\le n)\cdot d\}\). Let's discuss a specific example for simpicity.

If there is a tuple \(h_{i-1}\), \(h_i\) and \(h_{i+1}\) where \(h_{i-1}-h_i>d\) and \(h_{i+1}-h_i>d\). Then, if you want to adjust their heights, the cost-least way is to \(h_i \rightarrow \min\{h_{i-1},h_{i+1}\}-d\). Then, if you have an answer that isn't \(h_{i-1}+x\cdot d\) or \(h_{i+1}+x\cdot d\), the answer will become larger, which is easy to prove.

The other cases are simmilar to this one, so the observation is true as the case when \(h_i'\notin\{h_{j \ (1\le j \le n)}+x (-n\le x\le n)\cdot d\}\) is never the minimum answer.


With this observation, we can think of an \(O(n^5)\) code.

Step 3

Try optimizing \(O(n^5)\) into \(O(n^3)\). It is easy to notice that we can use a monotonous queue to optimize \(O(n^2)\) into \(O(1)\) and thus the whole complexity \(O(n^3)\).

Code

标签:le,min,cdot,Step,12170,answer,UVA,dp
From: https://www.cnblogs.com/SFlyer/p/17600174.html

相关文章

  • UVA10702 Travelling Salesman 题解
     UVA10702TravellingSalesman题解题面:有个旅行的商人,他每到一个的新城市,便卖掉所有东西再购买新东西,从而获得利润。从某城市A到某城市B有固定利润(B 到A 的利润可能不同)。已知城市可以重复到达,从S 点出发,经过T 个城市,有E个城市能作为终点,求最大的利润。先定义......
  • uva 784 Maze Exploration(DFS遍历图)
                            uva784MazeExplorationmaze(迷宫)ofrectangular(矩形的)roomsisrepresentedonatwodimensional(空间的)gridasillustrated(阐明)infigure1a.Eachpointofthegridisrepresentedbyacharacter.Thepoint......
  • uva 579 ClockHands(几何+水题)
                     uva579ClockHandsThemedievalinterestinmechanicalcontrivancesiswellillustratedbythedevelopmentofthemechanicalclock,theoldestofwhichisdrivenbyweightsandcontrolledbyaverge,anoscillatingarmengagin......
  • uva 12299 RMQ with Shifts(线段树单点更新初步应用)
                                 uva12299RMQwithShiftsInthetraditionalRMQ(RangeMinimumQuery)problem,wehaveastaticarrayA.Thenforeachquery(L,R)(LR),wereporttheminimumvalueamongA[L],A[L+1],...,A[R].N......
  • uva 10061 How many zero's and how many digits ?(在不同进制下分解因子)
                             uva10061Howmanyzero'sandhowmanydigits?Givenadecimalintegernumberyouwillhavetofindouthowmanytrailingzeroswillbethereinitsfactorialinagivennumbersystemandalsoyouwillhaveto......
  • uva 156 Ananagrams(字符串+STL应用)
                         uva156AnanagramsMostcrosswordpuzzlefansareusedtoanagrams--groupsofwordswiththesamelettersindifferentorders--forexampleOPTS,SPOT,STOP,POTSandPOST.Somewordshoweverdonothavethisattribute,......
  • UVA??? 考试 Exam
    本来这篇题解是想在中考前写的,但是直到考前都没调出来,原因是pow()的精度感人。由于\(x\equiv0\pmod{a\cdotb}\),令\(c=\dfrac{x}{ab}\),答案即\(abc\len\)的无序三元组\((a,b,c)\)数量。考虑把无序转成有序,即\(a\leb\lec\),但显然会算少,分\(4\)种情况讨论:\(a=b=c=......
  • UVA10791 最小公倍数的最小和 Minimum Sum LCM 题解
    前言长沙市一中8机房0714模拟测1。传送门blog思路本题思路,首先我们先看$\operatorname{lcm}$,明显要使得这些数的$\operatorname{lcm}=n$那么我们就需要所有的数的质因子必须包含$n$的质因子。若$1\lea,b$,则$a\timesb\gea+b$,所以我们就有了策略。将同一个质因......
  • UVA210 双端队列模拟并行程序
    #include<iostream>#include<algorithm>#include<string>#include<sstream>#include<vector>#include<queue>#include<cstring>usingnamespacestd;constintmaxn=10001;//uva210:题意模拟n个程序的并行执行,有赋值,打印,lock,unlock,......
  • uvalive 3363(区间dp)
    题意:给出一个字符串,问最多能缩减到多短。缩减方式比如:aaaaabbbb->5(a)4(b)nowletsgogogoletsgogogo->now2(lets3(go))题解:区间dp,f[l][r]表示从l到r最多缩减到的长度。#include<stdio.h>#include<string.h>#include<algorithm>usingnamespacestd;constintN=2......