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做... 我就是凭着概率的直觉写的,还好这题不算难. 这题的重点在于考虑概率:他们喜相逢的概率是多少?考虑超几何分布 ...
随机推荐
- node爬虫(简版)
做node爬虫,首先像如何的去做这个爬虫,首先先想下思路,我这里要爬取一个页面的数据,要调取网页的数据,转换成页面格式(html+div)格式,然后提取里面独特的属性值,再把你提取的值,传送给你的页面 ...
- minGw64编译Qt时遇到too many sections问题
minGw64编译Qt时遇到too many sections问题: 修改\Src\qtbase\mkspecs\win32-g++\qmake.conf中 QMAKE_CFLAGS ...
- Wash!!(HDU_6000)
传送门:Wash! 题意:有n台洗衣机,m台烘干机,给出了每台机器处理意见衣服的时间,而且没见机器同时只能处理一件衣服.问如何选择机器才能使洗完衣服的时间最短. 思路:建两个优先队列,一个表示洗衣机, ...
- UNIX环境C语言进程通信
一.信号管理 1.函数signal signal函数是UNIX系统信号机制最简单的接口 #include <signal.h> typedef void (*sighandler_t)(i ...
- int (*a)[10] 和 int *a[10] 的区别
int *a[10] :指针数组.数组a里存放的是10个int型指针 int (*a)[10] :数组指针.a是指针,指向一个数组.此数组有10个int型元素 int *a[10] 先找到声明符a,然 ...
- cs229_part4
又到了一节很重要的课,因为这个学习理论是从统计角度为机器学习算法提供了一个理论基础. 学习理论 问题背景 先回顾一下我们第一节课提到的机器学习的组成: 第一节课只是简单的提了一下,现在我们要真正来分析 ...
- ASP.NET MVC 通用角色权限管理系统
RightControl 介绍 .NET 通用后台角色权限管理系统,已完成.项目地址:http://106.14.77.184/Admin/Login 码云地址:https://gitee.com/L ...
- Windows phone UI虚拟化和数据虚拟化(二)
书接上回的Windows phone UI虚拟化和数据虚拟化(一)我们学习了wp的ui虚拟化.今天来和大家分享一下wp的数据虚拟化. 并同时感谢我的同事dgwutao在编写此文时给我的巨大帮助,3ks ...
- docker.io/centos安装phpstudy
1.准备工作 yum install vimyum install wget yum install make yum -y install bzip2 yum install m4 yum inst ...
- STM32F407 ADC 个人笔记
1. ADC概述(STM32F4xx系列) 3 个 ADC 可分别独立使用 也可使用双重/三重模式(提高采样率) 2 个通道组 规则通道:相当于正常运行的程序 注入通道:相当于中断(可以打断规则通道的 ...