cf540D. Bad Luck Island(概率dp)
题意
岛上有三个物种:剪刀$s$、石头$r$、布$p$
其中剪刀能干掉布,布能干掉石头,石头能干掉剪刀
每天会从这三个物种中发生一场战争(也就是说其中的一个会被干掉)
问最后仅有$s/r/p$物种生存的概率
Sol
还是想复杂了啊,我列的状态时$f[i][j], g[i][j],t[i][j]$分别表示第$i$天,$j$个$s, r, p$活着的概率
然而转移了一下午也没转移出来。。
标算比我简单的多,直接设$f[i][j][k]$表示剩下$i$个$s$,$j$个$r$,$k$个$p$的概率
然后记忆化搜索一下
/* */
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/hash_policy.hpp>
#define Pair pair<int, int>
#define MP(x, y) make_pair(x, y)
#define fi first
#define se second
#define int long long
#define LL long long
#define ull unsigned long long
#define rg register
#define pt(x) printf("%d ", x);
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<22, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 22)], *p1 = buf, *p2 = buf;
//char obuf[1<<24], *O = obuf;
//void print(int x) {if(x > 9) print(x / 10); *O++ = x % 10 + '0';}
//#define OS *O++ = ' ';
using namespace std;
//using namespace __gnu_pbds;
const int MAXN = 1e6 + , INF = 1e9 + , mod = 1e9 + ;
const double eps = 1e-;
inline int read() {
char c = getchar(); int x = , f = ;
while(c < '' || c > '') {if(c == '-') f = -; c = getchar();}
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * f;
}
double a, b, c;
double f[][][];
double calca(int a, int b, int c) {
if(f[a][b][c]) return f[a][b][c];
if(a == ) return f[a][b][c] = ;
if(a && (!b) && (!c)) return f[a][b][c] = ;
double down = a * b + b * c + a * c, ans = ;
if(a && b) ans += (double) a * b / down * calca(a, b - , c);
if(b && c) ans += (double) b * c / down * calca(a, b, c - );
if(a && c) ans += (double) a * c / down * calca(a - , b, c);
return f[a][b][c] = ans;
}
double calcb(int a, int b, int c) {
if(b == ) return f[a][b][c] = ;
if((!a) && b && (!c)) return f[a][b][c] = ;
if(f[a][b][c]) return f[a][b][c];
double down = a * b + b * c + a * c, ans = ;
if(a && b) ans += (double) a * b / down * calcb(a, b - , c);
if(b && c) ans += (double) b * c / down * calcb(a, b, c - );
if(a && c) ans += (double) a * c / down * calcb(a - , b, c);
return f[a][b][c] = ans;
}
main() {
a = read(); b = read(); c = read();
double a1 = , a2 = ;
printf("%.10lf ", a1 = calca(a, b, c)); memset(f, , sizeof(f));
printf("%.10lf ", a2 = calcb(a, b, c));
printf("%.10lf", - a1 - a2);
return ;
}
/*
2 2 1
1 1
2 1 1
*/
cf540D. Bad Luck Island(概率dp)的更多相关文章
- 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 (概率DP)
题意:会出石头.剪刀.布的人分别有r,s,p个,他们相互碰到的概率相同,输的人死掉,问最终活下去的人是三种类型的概率 设状态dp(i,j,k)为还有i个石头,j个剪刀,k个布时的概率,dp(r,s,p ...
- CF540D Bad Luck Island(期望dp)
传送门 解题思路 比较容易的一道期望\(dp\),设\(f[i][j][k]\)表示石头\(i\)个,剪刀\(j\)个,步子\(l\)个.然后转移的时候用组合数算一下就好了. 代码 #include& ...
- Codeforces 540D Bad Luck Island - 概率+记忆化搜索
[题意] 一个岛上有三种生物A,B,C,各有多少只在输入中会告诉你,每种最多100只 A与B碰面,A会吃掉B, B与C碰面,B会吃掉C, C与A碰面,C会吃掉A...忍不住想吐槽这种环形食物链 碰面是 ...
- CF540D Bad Luck Island
嘟嘟嘟 看到数据范围很小,就可以暴力\(O(n ^ 3)\)dp啦. 我们令\(dp[i][j][k]\)表示这三种人分别剩\(i, j, k\)个的概率.然后枚举谁挂了就行. 这里的重点在于两个人相 ...
- 【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 B. Bad Luck Island(概率dp)
题目描述: Bad Luck Island time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
随机推荐
- centos7.3下配置本地yum仓库
部署openstack时,网络yum源安装慢,而且经常中的提示找不到mirrors,所以配置一个本地的安装源很有必要,来解决这个揪心的问题. 安装:yum install yum-utils crea ...
- Python+Selenium----使用HTMLTestRunner.py生成自动化测试报告1(使用IDLE)
1.说明 自动化测试报告是一个很重要的测试数据,网上看了一下,使用HTMLTestRunner.py生成自动化测试报告使用的比较多,但是呢,小白刚刚入手,不太懂,看了很多博客,终于生成了一个测试报告, ...
- (转)linux route命令详解
linux route命令详解 原文:https://www.cnblogs.com/lpfuture/p/5857738.html && http://blog.csdn.n ...
- java编程如何实现2017-01-16 22:28:26.0这样的时间数据,转换成2017:01:16:22:28:26这样的时间数据
不多说,直接上干货! timereplace.java package zhouls.bigdata.DataFeatureSelection.util; /* * 这个程序,是用来做补充的 */ p ...
- Spark Mllib里相似度度量(基于余弦相似度计算不同用户之间相似性)(图文详解)
不多说,直接上干货! 常见的推荐算法 1.基于关系规则的推荐 2.基于内容的推荐 3.人口统计式的推荐 4.协调过滤式的推荐 协调过滤算法,是一种基于群体用户或者物品的典型推荐算法,也是目前常用的推荐 ...
- [WPF自定义控件库]简单的表单布局控件
1. WPF布局一个表单 <Grid Width="400" HorizontalAlignment="Center" VerticalAlignment ...
- Visual Studio 2015 实用插件推荐
-1000.EntityFramework Reverse POCO Generator(EF Code First 的必备神器) Reverse engineers an existing data ...
- a标签嵌套a标签效果的两种解决方案
<!-- a标签进行嵌套的时候 --> <a href="#outer">outerA <a href="#inner">i ...
- JS性能优化的那点事
1:减少查找次数,把需要查找的内容先提取出来,全部添加计算完成后,再统一查找一次即可,如下面例子: <script> window.onload = function () { var s ...
- zip man man.config
zip man man.config zip -r zip1 man.config man.zip gzip a tar -cvf test.tar /home/* tar -tf test.tar ...