欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

cf540D. Bad Luck Island(概率dp)

程序员文章站 2022-12-24 08:48:32
题意 岛上有三个物种:剪刀$s$、石头$r$、布$p$ 其中剪刀能干掉布,布能干掉石头,石头能干掉剪刀 每天会从这三个物种中发生一场战争(也就是说其中的一个会被干掉) 问最后仅有$s/r/p$物种生存的概率 Sol 还是想复杂了啊,我列的状态时$f[i][j], g[i][j],t[i][j]$分别 ......

题意

岛上有三个物种:剪刀$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
*/