Chosen by god FZU - 2301

Everyone knows there is a computer game names "hearth stone", recently xzz likes this game very much. If you want to win, you need both capacity and good luck.

There is a spell card names "Arcane Missiles", which can deal 3 damages randomly split among all enemies.

xzz have a "Arcane Missiles Plus" can deal n damage randomly split among all enemies. The enemy battle field have only two characters: the enemy hero and enemy minion.

Now we assume the enemy hero have infinite health, the enemy minion has m health.

xzz wants to know the probability of the "Arcane Missiles Plus" to kill the enemy minion (the minion has not more than 0 health after "Arcane Missiles Plus"), can you help him?

Input

The first line of the input contains an integer T, the number of test cases. T test cases follow. (1 ≤ T ≤ 100000)

Each test case consists of a single line containing two integer n and m. (0 ≤ m ≤ n ≤ 1000)

Output

For each test case, because the probability can be written as x / y, please output x * y^-1 mod 1000000007. .(y * y^-1 ≡ 1 mod 10^9 + 7)

Sample Input

2
3 3
2 1

Sample Output

125000001
750000006

题意:你有一个法术具有n次伤害,每次伤害可以随机的对宠物或者英雄减少一滴血,问你杀死宠物的概率是多少?把最后的结果mod 1000000007

思路:你可以杀死宠物的情况为C(n,m),C(n,m+1),.....C(n,n) 所以分子为C(n,m)+C(n,m+1)+C(n,m+2)+...+C(n,n),

由于你有n 次机会,每次有两种选择,所以分母为 pow(2,n) ;由于除法取模 所以用到逆元,最后答案为C(n,m)+C(n,m+1)+C(n,m+2)+...+C(n,n)*pow(pow(2,n),mod-2)%mod;

注意取模

代码如下:

#include<stdio.h>
#include<algorithm>
#include<iostream>
#define ll long long
using namespace std;
const int mod =1e9+7;
const int maxn =1005;
ll C[maxn][maxn];
ll ans[maxn][maxn];
ll sum[maxn];
ll quck_pow(ll a,ll b)
{
    if(!b)return 1;
    ll mid=(quck_pow(a,b/2))%mod;
    if(b&1)return (mid%mod*mid%mod*a%mod)%mod;
    else return (mid%mod*mid%mod)%mod;
}
void init()
{
    for(int i=0;i<=maxn;i++)
    {
        C[i][0]=1;
        C[i][i]=1;
    }
    for(int i=2;i<=maxn;i++)
    {
        for(int j=1;j<i;j++)
        {
            C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
        }
    }
    for(int i=0;i<=maxn;i++)
    {
        sum[i]=quck_pow(quck_pow(2,i)%mod,mod-2)%mod;
    }
}
int main()
{
    int t;
    init();
    scanf("%d",&t);
    while(t--)
    {
        int n,m;
        scanf("%d%d",&n,&m);
        ll k=0;
        for(int i=m;i<=n;i++)
        {
            k=(C[n][i]+k)%mod;
        }
        printf("%lld\n",k*sum[n]%mod);
    }
    return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值