Try   HackMD

第七屆簡單的小競賽題解

pA. 解題愛老鼠(太空人老鼠)

ij 建一條
ci,j
的邊,跑一次 Floyd Warshall,可得到實際的花費
ci,j

建一張圖,

S 向所有
ai>C
的點建
(,)=(aiC,0)
的邊;所有
aj<C
的點向
T
(,)=(Caj,0)
的邊;所有
ai>C
的點向
aj<C
的點建
(,)=(,ci,j)
的邊。

跑一次最小費用流即為答案。

pB. 豬哥選總統

可以使用位元 dp,沒住人的格子以

1 表示,在所處矩形右界的格子也以
1
表示,轉移的時候只要看有沒有跟上一行的矩形對齊判斷是否要
+1

可以做到

O(n22m)

pC. 人生遊戲

可以參考康威生命遊戲,發現有一種會移動的狀態叫滑翔機,經過實驗三關分別可以這樣構造:

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

pD. 送外賣2

直接讓最大的那條邊變

5 倍,然後做最大生成樹,複雜度
O(mlog(m))

pE. 合併排序

假設合併時左邊陣列大小

x,右邊陣列大小
y
,排法共有
Cxx+y
種。

分成最大值在左邊與在右邊的情況,如果在左邊,那不會呼叫 cmp 的次數會是連續一段最大值的長度,假設是

i,那有
Cy1x+yi1
種排法,期望值為
i=1x(x+yi)×Cy1x+yi1Cxx+y=xyy+1
,同理最大值在右邊的期望值為
xyx+1

dpn 為大小
n
陣列的答案,那
dpn=dpn2+dpn2+n2n2n2+1+n2n2n2+1