2019牛客多校第二场A-Eddy Walker

Eddy Walker

题目传送门

解题思路

因为走过所有的点就会停下来,又因为是从0出发的,所以当n>1时,在0停下来的概率为0,其他的为1/(n-1);

代码如下

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;

inline int read(){
    int res = 0, w = 0; char ch = 0;
    while(!isdigit(ch)){
        w |= ch == '-', ch = getchar();
    }
    while(isdigit(ch)){
        res = (res << 3) + (res << 1) + (ch ^ 48);
        ch = getchar();
    }
    return w ? -res : res;
}

template <typename A, typename B, typename C>
inline A fpow(A x, B p, C lyd){
    A ans = 1;
    for(; p; p >>= 1, x = 1LL * x * x % lyd)if(p & 1)ans = 1LL * x * ans % lyd;
    return ans % lyd;
}

ll get_inv(ll b, ll mod){
    return fpow(b, mod - 2, mod);
}

const int N = 100005;
const int mod = 1e9+7;

int main()
{
    int t;
    cin >> t;
    ll last = 1;
    while(t --){
        ll n, m;
        cin >> n >> m;
        ll ans;
        if(m)
            ans = 1 * get_inv(n - 1, mod) % mod;
        else {
            if(n > 1)
                ans = 0;
            else
                ans = 1;
        }
        cout << ans * last % mod << endl;
        last = ans * last % mod;
    }
    return 0;
}
posted @ 2019-07-26 19:43  whisperlzw  阅读(142)  评论(0编辑  收藏  举报