2019牛客暑期多校训练营(第二场)

A.Eddy Walker

题意: 给你长度为n的圈(共有n个点(0~n-1),按顺序形成一个环), 每次随机的向左走一步或者向右走一步, 问你最后将所有点走过至少一遍,最后一步停留在m点的概率是多少。

这题主要是很少有人能把题目读懂,像篇阅读理解一样的,看懂后就会发现你会发现落在0到n-1上的概率是相同的,T组样例,每次的概率都要乘以之前的概率,最后记得加上特判

#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
 
const int mod=1e9+7;
ll n, m, ans;

ll mod_pow(ll x, ll n)
{
    ll res = 1;
    while (n>0) {
        if (n&1) res = res*x%mod;
        x = x*x%mod;
        n >>= 1;
    }
    return res;
}
 
int main()
{
    int t;
    scanf("%d",&t);
     
    ans = 1;
    while(t--){
        scanf("%d%d",&n,&m);
        if(n==1 && m==0) ans *= 1;   
        else if(m==0) ans *= 0;
        else ans = (ans*mod_pow(n-1,mod-2))%mod;   
        printf("%lld\n",ans); 
    }
    return 0;
}
View Code

猜你喜欢

转载自www.cnblogs.com/wizarderror/p/11226316.html