0w1

Entries from 2016-03-02 to 1 day

TOI 排隊約瑟夫問題 ( DP + 代數分析 )

每次審判排頭有 d的機率死亡並被逐出隊伍,否則則返回隊尾。當排頭是最後一個人的時候審判不會再進行。 現在給你隊伍初始的人數 n,你的編號 k( 注意 0 ≤ k 你存活( 成為隊伍裡最後的人 )的機率為多少? 我們先令 P( i )為隊伍裡有 i人的情況下,自己是第一…

CFR Educational 1 D. Igor In the Museum ( Easy BFS )

Problem - D - Codeforces Simply simulating will be alright. #include <bits/stdc++.h> using namespace std; const int MAXN = 1e3 + 3; const int MAXM = 1e3 + 3; const int MAXK = 1e6 + 6; const int dx[] = { 0, 1, 0, -1 }; const int dy[] = { 1, 0, -1, 0 }; in</bits/stdc++.h>…

CFR 313 D. Ilya and Roads ( DP )

Problem - D - Codeforces We can first precompute mincost array where mincost[ i ][ j ]: minimum cost required to, fix all holes that hadn't yet been, starting from i until j dp[ i ][ j ]: minimum cost required when, finished examining i ho…

IOI'94 The Primes ( 暴搜 + 枚舉順序剪枝 )

PEG Judge - IOI '94 - The Primes 不停的 TLE,原來枚舉的順序影響這麼大呢。。 首先最好枚舉兩個對角線,因為他們影響的最大。 接著枚舉外面兩行,所以我們要事先紀錄中間那三個數字總和為多少且頭尾為多少的質數有哪些。 再來我們發現這兩個格子可以 O( 1…