【FZU-2303】Mind control

There is a wonderful country where people like eating very much. Each person has exactly one direct follower while the follower’s follower is also follower of this man (of course the most unattractive man doesn’t have his follower).

And you find some amazing cake, if you give it to a person, you can have the trust of this person and all his followers.

Now you want to give out M cakes randomly to N person (each person can get at most one cake), please calculate the expectation of the trust you have earned.

Because the answer can write as a / b, please output a * b^-1 mod 10^9 + 7. (b * b^-1 ≡ 1 mod 10^9 + 7)

Input
First line a single integer T indicating the number of cases. T<=1000000;

For each case, first line two number N and M described before. N, M<=1000000;

Output
A single integer indicating the expectation of the trust you have earned. (mod 1e9 + 7)

Sample Input
2
3 3
3 2
Sample Output
3
666666674

题意:从n个人中选m个,得分为这m个人中最大的编号,求随即选择的得分的数学期望。

  • 个人思路:

按照题意,我们先限定最高的编号,然后在这个编号下的编号中选出m-1个数。逐一选择每个最高编号,可以发现这种取法可以涵盖所有取法可能,猜想得到下面结论:
在这里插入图片描述
画杨辉三角验证发现成立:
在这里插入图片描述
按照题意,求数学期望,逐步化简,中间再次套用①公式,得到o(1)的结论:
在这里插入图片描述
得到结论后求个逆元就可以了。

#include<iostream>
#define rep(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

const int mod=1e9+7;
ll n,m;

ll qpow(ll x,ll k) {
    if(k==0) return 1;
    ll t=qpow(x,k/2);
    if(k&1) return t*t%mod*x%mod;
    else return t*t%mod;
}

void solve(ll ans=0) {
    cin>>n>>m;
    cout<<(n+1)*m%mod*qpow(m+1,mod-2)%mod<<endl;
}

int main() {
    ios::sync_with_stdio(false);
    int T;cin>>T;
    while(T--) solve();
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值