cf540D. Bad Luck Island(概率dp)

Posted zwfymqz

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 + 10, INF = 1e9 + 10, mod = 1e9 + 7;
const double eps = 1e-9;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < 0 || c > 9) {if(c == -) f = -1; c = getchar();}
    while(c >= 0 && c <= 9) x = x * 10 + c - 0, c = getchar();
    return x * f;
}
double a, b, c;
double f[101][101][101];
double calca(int a, int b, int c) {
    if(f[a][b][c]) return f[a][b][c];
    if(a == 0) return f[a][b][c] = 0;
    if(a && (!b) && (!c)) return f[a][b][c] = 1;
    double down = a * b + b * c + a * c, ans = 0;
    if(a && b) ans += (double) a * b / down * calca(a, b - 1, c);
    if(b && c) ans += (double) b * c / down * calca(a, b, c - 1);
    if(a && c) ans += (double) a * c / down * calca(a - 1, b, c);
    return f[a][b][c] = ans;
}
double calcb(int a, int b, int c) {
    if(b == 0) return f[a][b][c] = 0;
    if((!a) && b && (!c)) return f[a][b][c] = 1;
    if(f[a][b][c]) return f[a][b][c];
    double down = a * b + b * c + a * c, ans = 0;
    if(a && b) ans += (double) a * b / down * calcb(a, b - 1, c);
    if(b && c) ans += (double) b * c / down * calcb(a, b, c - 1);
    if(a && c) ans += (double) a * c / down * calcb(a - 1, b, c);
    return f[a][b][c] = ans;
}
main() {
    a = read(); b = read(); c = read();
    double a1 = 0, a2 = 0;
    printf("%.10lf ", a1 = calca(a, b, c)); memset(f, 0, sizeof(f));
    printf("%.10lf ", a2 = calcb(a, b, c)); 
    printf("%.10lf", 1 - a1 - a2);
    return 0;
}
/*
2 2 1
1 1
2 1 1
*/

以上是关于cf540D. Bad Luck Island(概率dp)的主要内容,如果未能解决你的问题,请参考以下文章

CF540D Bad Luck Island(期望dp)

CF540D Bad Luck Island

Codeforces 540 D Bad Luck Island

Codeforces 540D Bad Luck Island

540D - Bad Luck Island(概率DP)

CF 301div2 D. Bad Luck Island