AtCoder Beginner Contest 184 D - increment of coins

题目意思:

给定金币银币铜币各a,b,c枚数,每次等概率的抽取一枚钱币,如果抽中的是金币,那么金币的数量+1,银币,铜币一样。

问任意一种钱币的数量到达100次时,操作次数的期望是多少。

这是一道动态规划题目,可以看成是一个条件概率,最终任意一种钱币到达100时的情况,都会从前面若干个情况转移过来,最后算一下期望(操作次数*操作次数的概率)就好了。

// #pragma GCC optimize(2)
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <random>
#include <cctype>
#include <bitset>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define IO                       \
	ios::sync_with_stdio(false); \
	// cout.tie(0);
#define lson(x) (x << 1)
#define rson(x) (x << 1 | 1)
using namespace std;
// int dis[8][2] = {0, 1, 1, 0, 0, -1, -1, 0, 1, -1, 1, 1, -1, 1, -1, -1};
typedef unsigned long long ULL;
typedef long long LL;
typedef pair<int, int> P;
const int maxn = 1e2 + 10;
const int maxm = 1e7 + 10;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const LL mod = 998244353;
const double eps = 1e-8;
const double pi = acos(-1);
// int dis[4][2] = {1, 0, 0, -1, 0, 1, -1, 0};
// int m[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
double dp[maxn][maxn][maxn];
int main()
{
#ifdef WXY
	freopen("in.txt", "r", stdin);
	//  freopen("out.txt", "w", stdout);
#endif
	IO;
	int a, b, c;
	cin >> a >> b >> c;
	dp[a][b][c] = 1;
	for (int i = a; i <= 99; i++)
	{
		for (int j = b; j <= 99; j++)
		{
			for (int k = c; k <= 99; k++)
			{
				dp[i + 1][j][k] += dp[i][j][k] * (i) / (i + j + k);
				dp[i][j + 1][k] += dp[i][j][k] * (j) / (i + j + k);
				dp[i][j][k + 1] += dp[i][j][k] * (k) / (i + j + k);
			}
		}
	}
	double ans = 0;
	for (int i = 0; i <= 99; i++)
		for (int j = 0; j <= 99; j++)
		{
			ans += (dp[100][i][j] + dp[i][100][j] + dp[i][j][100]) * max(0, i + j + 100 - a - b - c);
		}
	printf("%.10lf", ans);
	return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值