HDU 4336 概率DP 状压
生活随笔
收集整理的這篇文章主要介紹了
HDU 4336 概率DP 状压
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
用d(S)表示所收集到卡片種類狀態(tài)為S時(shí)還需買多少包小浣熊(這是我YY的)的期望。
則有方程d(S) = 1 + (P(空) + P(有)) * d(S) + P(無) * d(T)
其中P(空)表示沒有收集到卡片,P(有)表示收集到的是已經(jīng)有的卡片,P(無)表示收集到新的卡片。
而且?P(空) +?P(有) +?P(無) = 1,T表示收集到新卡片后的狀態(tài)
整理以后得到d(S) = (1 + d(T)) / P(無)
1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <cstring> 5 using namespace std; 6 7 const int maxn = 25; 8 double d[1100000]; 9 double p[1100000]; 10 11 int main() 12 { 13 int n; 14 while(scanf("%d", &n) == 1 && n) 15 { 16 for(int i = 0; i < n; i++) scanf("%lf", p + i); 17 int tot = (1 << n) - 1; 18 d[tot] = 0; 19 for(int i = tot - 1; i >= 0; i--) 20 { 21 double wu = 0; 22 d[i] = 1; 23 for(int j = 0; j < n; j++) if((i & (1 << j)) == 0) 24 { 25 wu += p[j]; 26 d[i] += p[j] * d[i | (1 << j)]; 27 } 28 d[i] /= wu; 29 } 30 printf("%.6f\n", d[0]); 31 } 32 33 return 0; 34 } 代碼君?
轉(zhuǎn)載于:https://www.cnblogs.com/AOQNRMGYXLMV/p/4691566.html
新人創(chuàng)作打卡挑戰(zhàn)賽發(fā)博客就能抽獎(jiǎng)!定制產(chǎn)品紅包拿不停!總結(jié)
以上是生活随笔為你收集整理的HDU 4336 概率DP 状压的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: NXOpen.BlockStyler的一
- 下一篇: (转) vector的reserve和r