第七屆簡單的小競賽題解
對 建一條 的邊,跑一次 Floyd Warshall,可得到實際的花費 。
建一張圖, 向所有 的點建 的邊;所有 的點向 建 的邊;所有 的點向 的點建 的邊。
跑一次最小費用流即為答案。
可以使用位元 dp,沒住人的格子以 表示,在所處矩形右界的格子也以 表示,轉移的時候只要看有沒有跟上一行的矩形對齊判斷是否要 。
可以做到 。
可以參考康威生命遊戲,發現有一種會移動的狀態叫滑翔機,經過實驗三關分別可以這樣構造:
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 →
直接讓最大的那條邊變 倍,然後做最大生成樹,複雜度 。
假設合併時左邊陣列大小 ,右邊陣列大小 ,排法共有 種。
分成最大值在左邊與在右邊的情況,如果在左邊,那不會呼叫 cmp 的次數會是連續一段最大值的長度,假設是 ,那有 種排法,期望值為 ,同理最大值在右邊的期望值為 。
令 為大小 陣列的答案,那 。