LOJ#6342. 跳一跳(期望)
程序员文章站
2022-05-18 23:03:53
题意 $n \leqslant 10^5$ Sol 随便推一推就好了吧。。 $f[i] = \frac{f[i] + f[i +1] + \dots f[n]}{n - i + 1} + 1$ 移一下项,然后化一化,就做完了。。 然而这题卡空间MMP ......
题意
$n \leqslant 10^5$
sol
随便推一推就好了吧。。
$f[i] = \frac{f[i] + f[i +1] + \dots f[n]}{n - i + 1} + 1$
移一下项,然后化一化,就做完了。。
然而这题卡空间mmp
#include<cstdio> #include<algorithm> #include<iostream> //#define int long long #define pair pair<int, int> #define fi first #define se second #define mp(x, y) make_pair(x, y) using namespace std; const int maxn = 1e7 + 10, inf = 1e9 + 10, mod = 1e9 + 7; inline int read() { char c = getchar(); int x = 0, f = 1; while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();} while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * f; } int n; int inv[maxn]; main() { n = read(); int s = 0, now = 0; inv[1] = 1; for(int i = 2; i <= n; i++) inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod; for(int i = n - 1; i >= 1; i--) { now = 1ll * (s + n - i + 1) * inv[n - i] % mod; s = (s + now) % mod; } cout << (now + mod) % mod; return 0; } /* 10000000 */