题目链接:传送门 洛咕传送门 令 s u m w sumw sumw表示 w w w的前缀和。 显然的 d p dp dp方程: d p [ i ] = m i n ( d p [ j ] + ( h [ i ] − h [ j ] ) 2 + s u m w [ i − 1 ] − s u m w [ j ] ) dp[i]=min(dp[j]+(h[i]-h[j])^2+sumw[i-1]-
E. Rudolf and k Bridges 这道题需要使用到deque deque:双端队列,可以在前后存取元素。 题目要求连续造k座桥,那么只需要把每一座桥的建造成本记录一下,最后取其中和最小的连续k座桥的成本即可。 对于每一座桥计算他的建造成本: 用dp来做,这座桥的第j个位置的建造成本为dp[j]; dp[j]=dp[k]+a[i][j]+1;其中k是一个范围[j-k-1,j-1];
描述 Caocao was defeated by Zhuge Liang and ZhouYu in the battle of Chibi. But he wouldn't give up. Caocao's army still was not good at water battles, so he came up with another idea. He built many isl