CF540D Bad Luck Island
嘟嘟嘟
看到数据范围很小,就可以暴力\(O(n ^ 3)\)dp啦。
我们令\(dp[i][j][k]\)表示这三种人分别剩\(i, j, k\)个的概率。然后枚举谁挂了就行。
这里的重点在于两个人相遇的概率是多少,拿\(i, j\)举例,乍一看是\(\frac{i * j}{(i + j + k) * (i + j + k - 1)}\),但这里包含了同一种族相遇的概率,这种情况还应该转移到\(dp[i][j][k]\),这样无限循环下去还是到了这个状态。所以我们的概率不应该包含同一种人相遇的情况,或者说这是一个条件概率,那么就是\(\frac{i * j}{i * j + i * k + j * k}\)。
剩下两种人同理。
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
#include<assert.h>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define In inline
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-14;
const int maxn = 105;
In ll read()
{
ll ans = 0;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) last = ch, ch = getchar();
while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
if(last == '-') ans = -ans;
return ans;
}
In void write(ll x)
{
if(x < 0) x = -x, putchar('-');
if(x >= 10) write(x / 10);
putchar(x % 10 + '0');
}
In void MYFILE()
{
#ifndef mrclr
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
#endif
}
int n, m, l;
db f[maxn][maxn][maxn];
int main()
{
//MYFILE();
n = read(), m = read(), l = read();
f[n][m][l] = 1;
for(int i = n; i >= 0; --i)
for(int j = m; j >= 0; --j)
for(int k = l; k >= 0; --k)
if(f[i][j][k] > eps)
{
db tot = i * j + i * k + j * k;
if(i && k) f[i - 1][j][k] += f[i][j][k] * i * k / tot;
if(i && j) f[i][j - 1][k] += f[i][j][k] * i * j / tot;
if(j && k) f[i][j][k - 1] += f[i][j][k] * j * k / tot;
}
db ans = 0;
for(int i = 1; i <= n; ++i) ans += f[i][0][0];
printf("%.12lf ", ans);
ans = 0;
for(int i = 1; i <= m; ++i) ans += f[0][i][0];
printf("%.12lf ", ans);
ans = 0;
for(int i = 1; i <= l; ++i) ans += f[0][0][i];
printf("%.12lf\n", ans);
return 0;
}
CF540D Bad Luck Island的更多相关文章
- cf540D. Bad Luck Island(概率dp)
题意 岛上有三个物种:剪刀$s$.石头$r$.布$p$ 其中剪刀能干掉布,布能干掉石头,石头能干掉剪刀 每天会从这三个物种中发生一场战争(也就是说其中的一个会被干掉) 问最后仅有$s/r/p$物种生存 ...
- CF540D Bad Luck Island(期望dp)
传送门 解题思路 比较容易的一道期望\(dp\),设\(f[i][j][k]\)表示石头\(i\)个,剪刀\(j\)个,步子\(l\)个.然后转移的时候用组合数算一下就好了. 代码 #include& ...
- 【CF540D】 D. Bad Luck Island (概率DP)
D. Bad Luck Island time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- cf.301.D. Bad Luck Island(dp + probabilities)
D. Bad Luck Island time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #301 (Div. 2) D. Bad Luck Island 概率DP
D. Bad Luck Island Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/540/pr ...
- CF#301 D:Bad Luck Island (概率dp)
D:Bad Luck Island 一个岛上有r个石头,s个剪子,p个布,他们之间随机挑出两个相遇,如果不是相同物种,就会有一个消失,分别求出最后这座岛上只剩下一个物种的概率. 我们用dp[i][j] ...
- CF 540D——Bad Luck Island——————【概率dp】
Bad Luck Island time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- CodeForces - 540D Bad Luck Island —— 求概率
题目链接:https://vjudge.net/contest/226823#problem/D The Bad Luck Island is inhabited by three kinds of ...
- Codeforces 540 D Bad Luck Island
Discription The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors andp pap ...
随机推荐
- 项目遇到的问题:页面c:forEach循环的数据进行计算传回后台并保持到数据库
应该还有更简单的方法 但是我不晓得 手动给文本框输入数据保存到数据库 A表 :通过订单编号 查询数据获得 B表 :通过A表中的字段查询遍历获得 问题: 手动输入文本框内容 保存到数据库 页面form提 ...
- 面试经典算法:快速排序Golang实现
Golang快速排序 定义 快速排序由C. A. R. Hoare在1962年提出.快速排序是对冒泡排序的一种改进,采用了一种分治的策略. 基本思想 通过一趟排序将要排序的数据分割成独立的两部分,其中 ...
- VS App_Code文件夹下的类文件不能直接被调用的解决方法
如下图所示,新建的类不能直接使用,会显示报错,检查命名空间什么的,未果 通过百度搜索,发现这么一篇文章:https://blog.csdn.net/younghaiqing/article/detai ...
- C# 第一次做项目。一些经验总结。
这是我的第一篇博客,写得不好望大家多多包涵. 初学C#2个多月,拿着老师给的项目,试着做了做,发现自己在编程方面有很多陋习与编程知识方面的不足. 首先是没有遵守某一个设计模式,这导致我想到哪里就做到了 ...
- ASP.NET WEB应用程序(.network4.5)MVC Razor视图引擎2 视图模板页
https://www.cnblogs.com/xlhblogs/archive/2013/06/09/3129449.html MVC Razor模板引擎 @RenderBody.@RenderPa ...
- vue-cli搭建vue项目环境
该篇文章是继https://www.cnblogs.com/qing-5/p/11321585.html来写 1.打开终端,输入指令"npm install --global vue-cli ...
- InnoDB引擎中的索引与算法9
5.1 InnoDB支持以下几种常见的索引: B+树索引 全文索引 哈希索引(自适应哈希索引) 关于哈希索引的说明: -- 1.InnoDB的哈希索引是自适应的,其根据表的使用情况自动生成哈希索引,不 ...
- zookeeper:2
单机环境下安装: 下载地址:http://apache.fayea.com/zookeeper/stable/ 解压zookeeper :tar -zxvf zookeeper-3.4.10.tar. ...
- Python更改pip源
Python更改pip源 pip源有以下 新版ubuntu要求使用https源,要注意.清华:https://pypi.tuna.tsinghua.edu.cn/simple阿里云:http://mi ...
- 安装sass时遇到Failed to build gem native extension
错误信息 执行命令: sudo gem install sass时遇到下面的错误信息 Building native extensions. This could take a while... ER ...