"Hdoj" "4336" Card Collector

Source: Internet
Author: User

Probability dp/mathematical expectation/pressure dp/tolerance principle

The 14th question in Kuangbin summary

What a wonderful way to do it ... The kuangbin of the code to see the good ...

1 //hdoj 43362#include <cstdio>3 #defineRep (i,n) for (int i=0;i<n;++i)4 #defineF (i,j,n) for (int i=j;i<=n;++i)5 #defineD (i,j,n) for (int i=j;i>=n;--i)6 Const intn= A;7 8 Doublep[n],f[1<<N];9 intMain () {Ten     intN; One      while(SCANF ("%d", &n)! =EOF) { A         Doublett=0.0; - Rep (i,n) { -scanf"%LF",&p[i]); thett+=P[i]; -         } -tt=1-tt; -f[(1<<n)-1]=0; +D (I, (1<<n)-2,0){ -             Doublex=0, sum=1.0; + Rep (j,n) A                 if(I & (1&LT;&LT;J)) x+=P[j]; at                 ElseSum+=p[j]*f[i| (1<<j)]; -f[i]=sum/(1-tt-x); -         } -printf"%.5lf\n", f[0]); -     } -     return 0; in}
View Code (probability dp)
1 //hdoj 43362#include <cstdio>3 #defineRep (i,n) for (int i=0;i<n;++i)4 #defineF (i,j,n) for (int i=j;i<=n;++i)5 6 Doublep[ A];7 intMain () {8     intN;9      while(SCANF ("%d", &n)! =EOF) {TenRep (i,n) scanf ("%LF",&p[i]); One         Doubleans=0; A          for(intI=1;i< (1<<n); + +i) { -             intCnt=0;Doublesum=0; -Rep (J,n)if(i& (1<<j)) { thesum+=P[j]; -cnt++; -             } -             if(cnt&1) ans+=1.0/sum; +             Elseans-=1.0/sum; -         } +printf"%.5lf\n", ans); A     } at     return 0; -}
View Code (Repulsion principle)

"Hdoj" "4336" Card Collector

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.