cf540D. Bad Luck Island(概率dp)

2018-09-05 07:42:39来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

题意

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

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:cf550C. Divisibility by Eight(结论)

下一篇:cf492E. Vanya and Field(扩展欧几里得)