Dwango Programming Contest 6th -B
Posted 19992147orz
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Dwango Programming Contest 6th -B相关的知识,希望对你有一定的参考价值。
期望
按每个空隙计算 对于第$i$个空隙 对于第$j$个跨过这段的概率是$frac{1}{i-j+1}$ 因为跨过当且仅当$[j+1,i]$之间都不先于$j$合并 求一个逆元前缀和即可

#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5, P = 1e9 + 7; int n; int x[maxn], inv[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n; for(int i = 1; i <= n; ++i) { cin >> x[i]; } inv[1] = 1; for(int i = 2; i <= n; ++i) { inv[i] = 1LL * (P - P / i) * inv[P % i] % P; } for(int i = 2; i <= n; ++i) { inv[i] = (inv[i] + inv[i - 1]) % P; } int ans = 0; for(int i = 1; i < n; ++i) { ans = (ans + 1LL * inv[i] % P * (x[i + 1] - x[i]) % P) % P; } for(int i = 1; i < n; ++i) { ans = 1LL * ans * i % P; } cout << ans << ‘ ‘; return 0; }
以上是关于Dwango Programming Contest 6th -B的主要内容,如果未能解决你的问题,请参考以下文章
Dwango Programming Contest 6th C
Dwango Programming Contest 6th Task C. Cookie Distribution