Guest User

Untitled

a guest
Mar 5th, 2012
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <map>
  5.  
  6. using namespace std;
  7.  
  8. map <vector<int>,double> a;
  9. double p;
  10.  
  11. double calc(vector <int> aa){
  12.     if (aa[12]){
  13.         return 1;
  14.     }
  15.     if (aa[13]==6 || aa[14]==6){
  16.         return 0;
  17.     }
  18.     if (a.find(aa)!=a.end()){
  19.         return a[aa];
  20.     }
  21.     double ans=0;
  22.     for (int i=0;i<13;i++){
  23.         int j=i;
  24.         while (aa[j]){
  25.             j=(j+1)%13;
  26.         }
  27.         aa[j]=1;
  28.         aa[13]++;
  29.         ans+=p*calc(aa);
  30.         aa[13]--;
  31.         aa[14]++;
  32.         ans+=(1-p)*calc(aa);
  33.         aa[14]--;
  34.         aa[j]=0;
  35.     }
  36.     ans/=13.0;
  37.     a[aa]=ans;
  38.     return ans;
  39. }
  40.  
  41. int main(){
  42.     vector <int> aa(15,0);
  43.     cin>>aa[13]>>aa[14];
  44.     for (int i=0;i<aa[13]+aa[14];i++){
  45.         int t;
  46.         cin>>t;
  47.         t--;
  48.         aa[t]=1;
  49.     }
  50.     cin>>p;
  51.     if (aa[12]){
  52.         cout<<0.0;
  53.         return 0;
  54.     }
  55.     cout<<calc(aa);
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment