Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <vector>
- #include <map>
- using namespace std;
- map <vector<int>,double> a;
- double p;
- double calc(vector <int> aa){
- if (aa[12]){
- return 1;
- }
- if (aa[13]==6 || aa[14]==6){
- return 0;
- }
- if (a.find(aa)!=a.end()){
- return a[aa];
- }
- double ans=0;
- for (int i=0;i<13;i++){
- int j=i;
- while (aa[j]){
- j=(j+1)%13;
- }
- aa[j]=1;
- aa[13]++;
- ans+=p*calc(aa);
- aa[13]--;
- aa[14]++;
- ans+=(1-p)*calc(aa);
- aa[14]--;
- aa[j]=0;
- }
- ans/=13.0;
- a[aa]=ans;
- return ans;
- }
- int main(){
- vector <int> aa(15,0);
- cin>>aa[13]>>aa[14];
- for (int i=0;i<aa[13]+aa[14];i++){
- int t;
- cin>>t;
- t--;
- aa[t]=1;
- }
- cin>>p;
- if (aa[12]){
- cout<<0.0;
- return 0;
- }
- cout<<calc(aa);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment