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做... 我就是凭着概率的直觉写的,还好这题不算难. 这题的重点在于考虑概率:他们喜相逢的概率是多少?考虑超几何分布 ...
随机推荐
- ios之coredata(二)
上面一篇文章介绍了coredata的有关基本概念,由于大部分是参考别人文章中的内容,所以感觉有点虚,而且估计也是比较难以理解,下面这篇文章通俗一点说说学习coredata后的一些理解,然后给出一个简单 ...
- UVa-12096-集合栈计算机
这题的话,我们读入操作之后,首先对于空集就是初始化为空. 我们可以使用typedef 对于 set 重命名为Set,这样就可以直接用Set()的语法进行空集的初始化了. 这题主要是对于集合的处理,我们 ...
- atlas 日志分析脚本
#!/usr/bin/env python # encoding: utf-8 #@author: 东哥加油! #@file: log_analyze.py #@time: 2018/8/23 17: ...
- Loadrunner中web脚本转成JavaVuser脚本
先用web方式录制好脚本,进行参数化,关联验证等操作,之后执行以下步骤: 1)将要转换的web脚本复制出来并保存到web.txt中2)参数界定符部分需要由{}手动修改成<>,包括参数化的和 ...
- 【MySQL】浅谈 varchar(N)
一 前言 varchar(N) N代表什么意思,能存放多少个中文字符?属于老生常谈的问题了,今天又被一个开发同事问我关于这个问题,索性写一篇文章来具体介绍一下.二 理论知识 先说明一下 MySQL ...
- Java设计模式学习三-----工厂模式
工厂模式 工厂模式(Factory Pattern)是Java中最常用的设计模式之一.这种类型的设计模式属于创建型模式,它提供了一种创建对象的最佳方式. 在工厂模式中,创建对象时不会对客户端暴露创建逻 ...
- CI - Set CSRF Hash and Cookie
/** * Set CSRF Hash and Cookie * * @return string */ protected function _csrf_set_hash() { if ($this ...
- windows下的host工作原理
在Window系统中有个Hosts文件(没有后缀名),在Windows98系统下该文件在Windows目录,在Windows2000/XP系统中位于C:\Winnt\System32\Drivers\ ...
- I/O输入系统
I/O输入系统 计算机有两个主要任务:I/O操作与计算处理.在许多情况下,主要任务是I/O操作.而计算处理只是附带的. 操作系统在计算机I/O方面的作用是管理和控制I/O操作和I/O设备. 概述 对与 ...
- 洛谷P3759 - [TJOI2017]不勤劳的图书管理员
Portal Description 给出一个\(1..n(n\leq5\times10^4)\)的排列\(\{a_n\}\)和数列\(\{w_n\}(w_i\leq10^5)\),进行\(m(m\l ...