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 << ‘\n‘;
    return 0;
}

原文地址:https://www.cnblogs.com/19992147orz/p/12237096.html

时间: 2024-10-08 03:33:56

Dwango Programming Contest 6th -B的相关文章

Dwango Programming Contest 6th C

Cookie Distribution 题意概述 : 有 \(N\) 个孩子,用 \(K\) 天给孩子们发糖果 第 \(i\) 天有 \(a_i\) 个糖果,等概率地发给这 \(n\) 个孩子(每一天每个孩子最多可以获得一个糖果),设 \(K\) 天后第 \(i\) 个孩子获得的糖果为 \(c_i\) 求 \(\prod_{i = 1}^n c_i\) 的期望乘上 \(\prod_{i = 1}^n \binom N {a_i}\) ,答案对 \(10^9 + 7\) 取模.. \(N \le

Dwango Programming Contest 6th Task C. Cookie Distribution

The answer is number of N-tuples (d[1], d[2], ..., d[N]) in all outcomes, where d[i] means on which day the i-th child get a cookie. Now consider in how many outcomes is there a particular N-tuple (d[1], d[2], ..., d[N]) as described. The answer turn

[Dwango Programming Contest 6th C] Cookie Distribution

传送门 组合意义,妙啊(弱菜 swk 不会数数实锤了 考虑 \(\prod c_i\) 的组合意义,它代表每个孩子在他得到的饼干中选择一个拿出来,最终的方案数. 因此得到了一个几乎显然的 dp: 设 \(f_{i, j}\) 为前 \(i\) 天,有 \(j\) 个孩子已经 "选择了" 他的饼干的方案数.转移时枚举新增了 \(u\) 个孩子,则转移系数是一系列组合数,详见代码. #include <bits/stdc++.h> #define R register #def

Dwango Programming Contest V 翻车记

A:签到. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; #define ll long long #define N 110 char getc(){char c=getchar();while ((c<'A'||c&

【AtCoder】Dwango Programming Contest V题解

A - Thumbnail 根据题意写代码 #include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define pdi pair<db,int> #define mp make_pair #define pb push_back #define enter putchar('\n') #define space putchar(' ') #define

ZOJ 3703 Happy Programming Contest(0-1背包)

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3703 Happy Programming Contest Time Limit: 2 Seconds      Memory Limit: 65536 KB In Zhejiang University Programming Contest, a team is called "couple team" if it consists of only two s

Happy Programming Contest zoj3703 dp

Description In Zhejiang University Programming Contest, a team is called "couple team" if it consists of only two students loving each other. In the contest, the team will get a lovely balloon with unique color for each problem they solved. Sinc

ACM International Collegiate Programming Contest, Tishreen Collegiate Programming Contest (2018) Syria, Lattakia, Tishreen University, April, 30, 2018

ACM International Collegiate Programming Contest, Tishreen Collegiate Programming Contest (2018) Syria, Lattakia, Tishreen University, April, 30, 2018 Problem A. Can Shahhoud Solve it? Problem B. Defeat the Monsters Problem C. UCL Game Night Problem

The 2018 ACM-ICPC China JiangSu Provincial Programming Contest快速幂取模及求逆元

题目来源 The 2018 ACM-ICPC China JiangSu Provincial Programming Contest 35.4% 1000ms 65536K Persona5 Persona5 is a famous video game. In the game, you are going to build relationship with your friends. You have N friends and each friends have his upper b