码迷,mamicode.com
首页 > 其他好文 > 详细

cf540D. Bad Luck Island(概率dp)

时间:2018-09-02 18:51:40      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:ace   ++   cstring   make   就是   print   pair   mes   main   

题意

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

标签:ace   ++   cstring   make   就是   print   pair   mes   main   

原文地址:https://www.cnblogs.com/zwfymqz/p/9574442.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!