Bobby‘s Bet(概率)

obby and Betty have a bet. Betty bets Bobby that he cannot roll an S-sided die (having values 1 through S) and obtain a value ≥R on at least X out of Y rolls. Betty has a variety of dice with different numbers of sides S, and all her dice are fair (for a given die, each side’s outcome is equally likely). In order to observe statistically rare events while still giving Bobby a reason to bet, Betty offers to pay Bobby W times his bet on each encounter. For example, suppose Betty bets Bobby 1 bitcoin that he can’t roll at least a 5 on a 6-sided die at least two out of three times; if Bobby does, she would give him W=3 times his initial bet (i.e. she would give him 3 bitcoins). Should Bobby take the bet (is his expected return greater than his original bet)?

Input
Input begins with an integer 1≤N≤10000, representing the number of cases that follow. The next N lines each contain five integers, R, S, X, Y, and W. Their limits are 1≤R≤S≤20, 1≤X≤Y≤10, and 1≤W≤100.

Output
For each case, output “yes” if Bobby’s expected return is greater than his bet, or “no” otherwise. Bobby is somewhat risk averse and does not bet if his expected return is equal to his bet.

Sample Input 1 Sample Output 1
2
5 6 2 3 3
5 6 2 3 4
no
yes
Sample Input 2 Sample Output 2
3
2 2 9 10 100
1 2 10 10 1
1 2 10 10 2
yes
no
yes

#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long LL;
const LL N = 1e6 + 10;
LL f[25][25];
LL solve(LL a, LL b) {
    LL ans = 1;
    while (b) {
        if (b & 1) ans = ans * a;
        b >>= 1;
        a *= a;
    }
    return ans;
}
signed main() {
    ios::sync_with_stdio(false);
    for (LL i = 0; i <= 20; i++) {
        for (LL j = 0; j <= i; j++) {
            if (!j)
                f[i][j] = 1;
            else
                f[i][j] = f[i - 1][j] + f[i - 1][j - 1];
        }
    }
    LL t, m, n, l, r, x, y, w, b;
    cin >> t;
    while (t--) {
        double p = 0;
        cin >> m >> n >> l >> r >> w;
        LL x = n - m + 1;
        LL y = m - 1;
        b = solve(n, r);
        for (LL i = l; i <= r; i++) {
            p += 1.0 * f[r][i] * solve(x, i) * solve(y, r - i) / b;
        }
        if (p * w > 1)
            cout << "yes\n";
        else
            cout << "no\n";
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值