Codeforces 540 D Bad Luck Island
Discription
The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors andp papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and if they belong to different species, then one individual kills the other one: a rock kills scissors, scissors kill paper, and paper kills a rock. Your task is to determine for each species what is the probability that this species will be the only one to inhabit this island after a long enough period of time.
Input
The single line contains three integers r, s and p (1 ≤ r, s, p ≤ 100) — the original number of individuals in the species of rock, scissors and paper, respectively.
Output
Print three space-separated real numbers: the probabilities, at which the rocks, the scissors and the paper will be the only surviving species, respectively. The answer will be considered correct if the relative or absolute error of each number doesn't exceed 10 - 9.
Example
2 2 2
0.333333333333 0.333333333333 0.333333333333
2 1 2
0.150000000000 0.300000000000 0.550000000000
1 1 3
0.057142857143 0.657142857143 0.285714285714
方程的转移比较显然23333,问题是怎么消除后效性。
也就是,每次f[i][j][k] 有 (C(i,2) + C(j,2) + C(k,2))/C(i+j+k,2) 的概率走到自己,
那么我们用一下生成函数(1+p+p^2+...=1/(1-p))的基本性质就可以算出f[i][j][k]期望走到自己多少次
,然后再转移即可。
#include<bits/stdc++.h>
#define ll long long
#define D double
using namespace std;
D f[105][105][105];
int n,m,k,C[355]; inline void init(){
C[0]=C[1]=0;
for(int i=2;i<=320;i++) C[i]=C[i-1]+i-1;
} inline void dp(){
f[n][m][k]=1.00;
for(int i=n;i>=0;i--)
for(int j=m;j>=0;j--)
for(int u=k;u>=0;u--) if((i>0)+(j>0)+(u>0)>=2){
f[i][j][u]=f[i][j][u]*C[i+j+u]/(double)(C[i+j+u]-C[i]-C[j]-C[u]);
if(i) f[i-1][j][u]+=f[i][j][u]*i*u/(double)C[i+j+u];
if(j) f[i][j-1][u]+=f[i][j][u]*i*j/(double)C[i+j+u];
if(u) f[i][j][u-1]+=f[i][j][u]*j*u/(double)C[i+j+u];
}
} inline void output(){
D ans;
ans=0;
for(int i=1;i<=n;i++) ans+=f[i][0][0];
printf("%.11lf ",ans);
ans=0;
for(int i=1;i<=m;i++) ans+=f[0][i][0];
printf("%.11lf ",ans);
ans=0;
for(int i=1;i<=k;i++) ans+=f[0][0][i];
printf("%.11lf",ans);
} int main(){
init();
scanf("%d%d%d",&n,&m,&k);
dp();
output();
return 0;
}
Codeforces 540 D Bad Luck Island的更多相关文章
- 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 ...
- CodeForces - 540D Bad Luck Island —— 求概率
题目链接:https://vjudge.net/contest/226823#problem/D The Bad Luck Island is inhabited by three kinds of ...
- Codeforces B. Bad Luck Island(概率dp)
题目描述: Bad Luck Island time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- 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 ...
- 【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)
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
http://codeforces.com/problemset/problem/540/D 题目大意: 会出石头.剪刀.布的人分别有r,s,p个,他们相互碰到的概率相同,输的人死掉,问最终活下去的人 ...
- 「日常训练」Bad Luck Island(Codeforces Round 301 Div.2 D)
题意与分析(CodeForces 540D) 是一道概率dp题. 不过我没把它当dp做... 我就是凭着概率的直觉写的,还好这题不算难. 这题的重点在于考虑概率:他们喜相逢的概率是多少?考虑超几何分布 ...
随机推荐
- 使用Spring Cloud需要了解一些概念
Spring Cloud是一个基于Spring Boot实现的微服务架构开发工具,它为基于JVM的微服务开发中的配置管理.服务发现.断路器.智能路由.微代理.控制总线.全局锁.决策竞选.分布式会话和集 ...
- 使用Fiddler抓取IOS_APP的请求
首先在地址https://www.telerik.com/fiddler 下载我们需要的fiddler 在新窗口中写上一些信息然后点击[Download for Windows]进行下载: 安装成功后 ...
- curl学习笔记(以php为例)
一.demo,抓取百度页码代码: $url = 'https://www.baidu.com/'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RE ...
- grafana绘制图表
安装方法 系统为ubuntu16 1首先添加以下到/etc/apt/sources.list: deb https://packagecloud.io/grafana/stable/debian/ s ...
- day23 03 组合的例子
day23 03 组合的例子 一.用到组合的方式,编写一个圆环,并能够计算出它的周长和面积 from math import pi # 从内置函数里面导入pi # 先定义一个圆类 class Circ ...
- Django初学及mvt模型理解
Django是python语言用来做web项目的一个模板,创建Django项目之后会自动生成models,views和templates文件夹,又叫mvt框架 文件结构如下: Models:其中mod ...
- python--初识html前端
一.HTML文档结构 最基本的HTML文档: <!DOCTYPE html> <html lang="zh-CN"> #这个lang表示语言,zh-CN是中 ...
- centos 7.3安装教程
进入安装初始化界面 等待检查完就可以进入安装了,不想等待的按ESC退出,没关系的 语言这里我们推荐使用英文: 然后点击Continue继续 选择-系统SYSTEM-安装位置INSTALLTION DE ...
- 模板<最小生成树>
转载 最小生成树浅谈 这里介绍最小生成树的两种方法:Prim和Kruskal. 两者区别:Prim在稠密图中比Kruskal优,在稀疏图中比Kruskal劣.Prim是以更新过的节点的连边找最小值,K ...
- 【03】github的markdown语法
[03]github的markdown语法 https://guides.github.com/features/mastering-markdown/(下图)(魔芋:已录入) http://ma ...