CodeForces 540D Bad Luck Island (DP)
题意:一个岛上有石头,剪刀和布,规则就不用说了,问你最后只剩下每一种的概率是多少。
析:很明显的一个概率DP,用d[i][j][k]表示,石头剩下 i 个,剪刀剩下 j 个,布剩下 k 个,d[r][s][p] = 1,那状态转发方程怎么写呢?是这样的
如果石头减少了1,那么肯定是布干的,那么是哪个布干掉了哪个石头呢?这又是另一个问题,答案就是 i * k,那么总数就是 i * k + i * j + j * k。
最后再把各项加起来即可。
代码如下:
#include <iostream>
#include <cstdio> using namespace std;
const int maxn = 100 + 5;
double d[maxn][maxn][maxn]; int main(){
int r, p, s;
cin >> r >> s >> p;
d[r][s][p] = 1;
for(int i = r; i >= 0; --i){
for(int j = s; j >= 0; --j){
for(int k = p; k >= 0; --k){
// if(!i && !j && !k) continue;
double sum = i * j + i * k + k * j;
if(!sum) continue;
if(i && k) d[i-1][j][k] += d[i][j][k] * i * k / sum;
if(i && j) d[i][j-1][k] += d[i][j][k] * i * j / sum;
if(j && k) d[i][j][k-1] += d[i][j][k] * j * k / sum;
}
}
} double ansr = 0, ansp = 0, anss = 0;
for(int i = 1; i <= r; ++i) ansr += d[i][0][0];
for(int i = 1; i <= s; ++i) anss += d[0][i][0];
for(int i = 1; i <= p; ++i) ansp += d[0][0][i];
printf("%.12lf %.12lf %.12lf\n", ansr, anss, ansp);
return 0;
}
CodeForces 540D Bad Luck Island (DP)的更多相关文章
- CodeForces - 540D Bad Luck Island —— 求概率
题目链接:https://vjudge.net/contest/226823#problem/D The Bad Luck Island is inhabited by three kinds of ...
- codeforces 540D Bad Luck Island (概率DP)
题意:会出石头.剪刀.布的人分别有r,s,p个,他们相互碰到的概率相同,输的人死掉,问最终活下去的人是三种类型的概率 设状态dp(i,j,k)为还有i个石头,j个剪刀,k个布时的概率,dp(r,s,p ...
- Codeforces 540D Bad Luck Island - 概率+记忆化搜索
[题意] 一个岛上有三种生物A,B,C,各有多少只在输入中会告诉你,每种最多100只 A与B碰面,A会吃掉B, B与C碰面,B会吃掉C, C与A碰面,C会吃掉A...忍不住想吐槽这种环形食物链 碰面是 ...
- Codeforces 540D Bad Luck Island
http://codeforces.com/problemset/problem/540/D 题目大意: 会出石头.剪刀.布的人分别有r,s,p个,他们相互碰到的概率相同,输的人死掉,问最终活下去的人 ...
- 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 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 ...
- 540D - Bad Luck Island(概率DP)
原题链接:http://codeforces.com/problemset/problem/540/D 题意:给你石头.剪刀.布的数量,它们之间的石头能干掉剪刀,剪刀能干掉布,布能干掉石头,问最后石头 ...
- CF 540D Bad Luck Island
一看就是DP题(很水的一道紫题) 设\(dp[i][j][k]\)为留下\(i\)个\(r\)族的人,死去\(j\)个\(s\)族的人,死去\(k\)个\(p\)族的人的概率(跟其他的题解有点差别,但 ...
随机推荐
- idea 破解代码
下面是idea的破解方法,手动执行对应的main方法即可.亲测Idea 14 完美破解~~废话少说,上代码... package com.jd.serializable; import java.ma ...
- 第十章 Secret & Configmap (中)
10.3 在Pod中使用Secret 10.3.1 Volume方式 apiVersion: v1 kind: Pod metaata: name: mypod spec: containers: - ...
- Java复习——网络编程
Java从最开始就是支持网络编程的,也正是网络使Java得到发展繁荣.在这里我记录一下如何使用Java进行网络编程,什么是Socket以及Java实现TCP,UDP的编程模型. InetAddress ...
- Clustering Factor——索引的成本指标
使用索引是我们面对海量数据搜索是一种常用的手段.通过有效的索引访问,可以使我们更快的访问到需要的数据,减少物理.逻辑IO,从而提高系统性能.在CBO时代,Oracle对于提交SQL的执行路径是有所选择 ...
- gil基本介绍
一 引子 定义: In CPython, the global interpreter lock, or GIL, is a mutex that prevents multiple native t ...
- HBase快速上手
一.创建单节点HBase实例 https://hbase.apache.org/book.html#quickstart (一)jdk版本要求Java: HBase Version JDK 7 JDK ...
- 比XGBOOST更快--LightGBM介绍
xgboost的出现,让数据民工们告别了传统的机器学习算法们:RF.GBM.SVM.LASSO.........现在,微软推出了一个新的boosting框架,想要挑战xgboost的江湖地位.笔者尝试 ...
- myBaits association的使用
转自:https://blog.csdn.net/victor_cindy1/article/details/50194879 >
- 导出ppt中所有文本框
打开PPT,按ALT+F11打开VBA编辑器,(部分电脑FN+ALT+F11)在左面的工程视图里点击右键,选择插入->模块,添加一个模块,名字都不用改. 然后点击顶部的"工具" ...
- .net Core 2.0使用NLog
最近研究了一下NLog的使用方式,简单的入了一下门. 实现的功能,对于不同的日志,进行不同的记录,分别有系统运行日志,和个人在程序中写的异常日志.发布之后放在了IIS上.进行查看日志的信息 参考了两篇 ...