codeforces 540D Bad Luck Island (概率DP)
生活随笔
收集整理的這篇文章主要介紹了
codeforces 540D Bad Luck Island (概率DP)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
題意:會出石頭、剪刀、布的人分別有r,s,p個,他們相互碰到的概率相同,輸?shù)娜怂赖?#xff0c;問最終活下去的人是三種類型的概率
設(shè)狀態(tài)dp(i,j,k)為還有i個石頭,j個剪刀,k個布時的概率,dp(r,s,p)=1.0
狀態(tài)轉(zhuǎn)移方程:
d(i-1,j,k)+=d(i,j,k)*(i*k)/(i*j+i*k+j*k);
d(i,j-1,k)+=d(i,j,k)*(i*j)/(i*j+i*k+j*k);
d(i,j,k-1)+=d(i,j,k)*(j*k)/(i*j+i*k+j*k);
因為狀態(tài)dp(i,j,k)可以由dp(i+1,j,k)、dp(i,j+1,k)和dp(i,j,k+1)轉(zhuǎn)移過來,所以用+=
一個三重循環(huán)解決,復(fù)雜度O(n^3)
#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<cstring> #include<string> #include<stack> #include<queue> #include<deque> #include<set> #include<vector> #include<map> #include<functional>#define fst first #define sc second #define pb push_back #define mp(a,b) make_pair(a,b) #define mem(a,b) memset(a,b,sizeof(a)) #define lson l,mid,root<<1 #define rson mid+1,r,root<<1|1 #define lc root<<1 #define rc root<<1|1 #define lowbit(x) ((x)&(-x)) using namespace std;typedef double db; typedef long double ldb; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> PI; typedef pair<ll,ll> PLL;const int maxn = 5e5 + 100; const int maxm = 5e5 + 100; const int inf = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3f; const double eps = 1e-6; inline int read(){int num;char ch;while((ch=getchar())<'0' || ch>'9');num=ch-'0';while((ch=getchar())>='0' && ch<='9'){num=num*10+ch-'0';}return num; } double dp[101][101][101]; int main(){int r, s ,p;scanf("%d %d %d", &r, &s, &p);mem(dp, 0);dp[r][s][p] = 1;for(int i = r; i >= 1; i--){for(int j = s; j >= 1; j--){for(int k = p; k >= 1; k--){double sum = i*j + j*k + i*k;printf("%d %d %d %lf\n", i, j, k, dp[i][j][k]);dp[i-1][j][k] = dp[i][j][k]*(double)(i*k)/sum;dp[i][j-1][k] = dp[i][j][k]*(double)(i*j)/sum;dp[i][j][k-1] = dp[i][j][k]*(double)(j*k)/sum;}}}double ans1, ans2, ans3;ans1 = ans2 = ans3 = 0;for(int i = 1; i <= 100; i++){for(int j = 1; j <= 100; j++){ans1 += dp[i][j][0];ans2 += dp[0][i][j];ans3 += dp[j][0][i];}}printf("%.17lf %.17lf %.17lf", ans1, ans2, ans3);return 0; } /**/ View Code?
轉(zhuǎn)載于:https://www.cnblogs.com/wrjlinkkkkkk/p/9426225.html
總結(jié)
以上是生活随笔為你收集整理的codeforces 540D Bad Luck Island (概率DP)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql if--else
- 下一篇: GIT安装部署