Tranvick

Untitled

Apr 5th, 2012
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.85 KB | None | 0 0
  1. #pragma comment(linker, "/STACK:65777216")
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <cstdlib>
  5. #include <ctime>
  6. #include <cstdio>
  7. #include <algorithm>
  8. #include <cmath>
  9. #include <vector>
  10. #include <set>
  11. #include <stack>
  12. #include <map>
  13. #include <queue>
  14. #include <string>
  15. #include <memory.h>
  16. #include <iterator>
  17. #define y1 trololoy1
  18. #define y0 trololoy0
  19. #define mem(A,X) memset(A,X,sizeof(A))
  20. #define memo(A) memset(A,0,sizeof(A))
  21. #define forn(I,B) for (int I=1;I<=(B);I++)
  22. #define forg(H,V) for (int H=first[V];h;h=next[H])
  23. #define rep(I,B) for (int I=0;I<(B);I++)
  24. #define labs(X) (((X)>0)?(X):(-(X)))
  25. #define ropen(X) freopen(X,"r",stdin)
  26. #define wopen(X) freopen(X,"w",stdout)
  27. #define rwopen(X) freopen(X".in","r",stdin);freopen(X".out","w",stdout)
  28. #define pb push_back
  29. #define mp make_pair
  30. #define all(X) (X).begin(),(X).end()
  31. #define sqr(X) ((X)*(X))
  32.  
  33. using namespace std;
  34.  
  35. typedef pair <int,int> pii;
  36. typedef double ld;
  37. typedef long long ll;
  38. typedef pair <ll,ll> pll;
  39. typedef vector<int> vi;
  40. const int N=111111;
  41. const ll P=1000000000;
  42. const int INF=1111111111;
  43. const double eps=1e-9;
  44. const double pi=3.14159265358979;
  45.  
  46. double f[7][7][1<<12],p,ans;
  47. int n,m,start,lim=1<<12,nxt;
  48.  
  49. int main(){
  50.     cin>>n>>m;
  51.     rep(i,n+m){
  52.         int x;
  53.         cin>>x;
  54.         start|=1<<(x-1);
  55.         if (x==13){
  56.             puts("0.000000");
  57.             return 0;
  58.         }
  59.     }
  60.     cin>>p;
  61.     f[n][m][start]=1.0;
  62.     for (int sum=n+m;sum<=11;sum++)
  63.         for (int win=n;win<=5;win++){
  64.             int lose=sum-win;
  65.             if (lose>5 || lose<m) continue;
  66.             for (int msk=0;msk<lim;msk++){
  67.                 if (f[win][lose][msk]==0.0) continue;
  68.                 nxt=12;
  69.                 ans+=f[win][lose][msk]/13.0;
  70.                 for (int i=11;i>=0;i--){
  71.                     if (!(msk&(1<<i))) nxt=i;
  72.                     if (nxt==12) ans+=f[win][lose][msk]/13.0;
  73.                     else{
  74.                         f[win+1][lose][msk|(1<<nxt)]+=f[win][lose][msk]*p/13.0;
  75.                         f[win][lose+1][msk|(1<<nxt)]+=f[win][lose][msk]*(1.0-p)/13.0;
  76.                     }
  77.                 }
  78.             }
  79.         }
  80.     printf("%lf\n",ans);
  81.     return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment