luoguP3750 [六省联考2017]分手是祝愿 概率期望DP + 贪心
...........真的神状态了,没办法去想的状态...................
考试的时候选择$50$分贪心+$15$分状压吧,别的点就放弃算了........
令$f[i]$表示从最小步数为$i$时走到最小步数为$i - 1$的状态的期望步数
(所以题目中的$k$实际上是个提示...........................)
那么当$i > k$时,有$f[i] = \frac{i}{n} + \frac{n - i}{n} * (1 + f[i] + f[i + 1])$
移项后转移就是递推式了
当$i \leqslant k$时,有$f[i] = f[i + 1] + 1$
怎么求解初始状态的最小步数呢?
可以发现,我们一定是从$n$慢慢点到$1$最优
那么,$1$个点会不会被点就跟它的倍数有多少个$1$有关
倒叙枚举$i$,再枚举$i$的倍数看看就好了.....
复杂度$O(n \log n)$
#include <cstdio> #include <cstring> #include <iostream> using namespace std; extern inline char gc() { static char RR[23456], *S = RR + 23333, *T = RR + 23333; if(S == T) fread(RR, 1, 23333, stdin), S = RR; return *S ++; } inline int read() { int p = 0, w = 1; char c = gc(); while(c > '9' || c < '0') { if(c == '-') w = -1; c = gc(); } while(c >= '0' && c <= '9') p = p * 10 + c - '0', c = gc(); return p * w; } #define ri register int #define sid 200500 const int mod = 100003; int n, k, nj = 1, mis, ans; int inv[sid], f[sid], v[sid]; int main() { n = read(); k = read(); for(ri i = 1; i <= n; i ++) v[i] = read(); for(ri i = n; i >= 1; i --) for(ri j = i + i; j <= n; j += i) v[i] ^= v[j]; for(ri i = 1; i <= n; i ++) mis += v[i]; inv[1] = 1; for(ri i = 2; i <= n; i ++) inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod; for(ri i = 1; i <= n; i ++) nj = 1ll * nj * i % mod; for(ri i = n; i > k; i --) f[i] = (n + 1ll * (n - i) * f[i + 1] % mod) * inv[i] % mod; for(ri i = k; i; i --) f[i] = 1; for(ri i = 1; i <= mis; i ++) (ans += f[i]) %= mod; printf("%d\n", 1ll * ans * nj % mod); return 0; }
喵喵喵?喵喵喵! 喵喵喵......