B. Dreamoon and WiFi
Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon ' s smartphone and Dreamoon follows them.
Each command is one of the following and types:
- Go 1 unit towards the positive direction, denoted as ' + '
- Go 1 unit towards the negative direction, denoted as '-'
But the Wi-Fi condition is so poor that Dreamoon's smartphone reports some of the commands can ' t be recognized and Dreamoo N knows that some of them might even be wrong though successfully recognized. Dreamoon decides to follow every recognized command and toss a fair coin to decide those unrecognized ones (that means, he Moves to the 1 unit to the negative or positive direction with the same probability 0.5).
You are given a original list of commands sent by Drazil and List received by Dreamoon. What's the probability that Dreamoon ends in the position originally supposed to being final by Drazil ' s commands?
Input
The first line contains a string s1-the commands Drazil sends to Dreamoon, this string consists of The characters in the set {' + ','-'}.
The second line contains a string s2-the commands Dreamoon ' s smartphone recognizes, this string consist S of only the characters in the set {' + ', '-', '? '}. '? ' denotes an unrecognized command.
Lengths of strings is equal and does not exceed .
Output
Output a single real number corresponding to the probability. The answer would be a considered correct if its relative or absolute error doesn ' t exceed -9.
Sample Test (s)
input
++-+-
+-+-+
Output
1.000000000000
Note
For the first sample, both s1 and S2 'll leads Dreamoon to finish at thesame position + 1.
For the second Sample, s 1 will leads Dreamoon To-finish at position 0, while there is four possibilites for s 2: {" +-++ ", " +-+-", "+--+", "+---"} with ending position {+2, 0, 0,-2} respectively. So there are 2 correct cases out Of 4, so the probability of finishing at the correct position is 0.5.
For the third sample, s2 could only leads us to finish at positions {+1,-1,-3}, so the probability to fi Nish at the correct position + 3 is 0.
Test Instructions : give you two strings with +--only, representing +1,-1
The second string contains? may be + or--now ask you what the probability of the second string equals the first string is worth.
the correct: for no, direct sentence
Yes? We're going to have to do a lot of violence. Character length less than 11, duly violent
///1085422276#include <bits/stdc++.h>using namespacestd; typedefLong Longll;#defineMem (a) memset (A,0,sizeof (a))#defineMeminf (a) memset (A,127,sizeof (a));#defineTS printf ("111111\n");#definefor (I,A,B) for (int i=a;i<=b;i++)#defineForj (I,A,B) for (int i=a;i>=b;i--)#defineREAD (a,b,c) scanf ("%d%d%d", &a,&b,&c)#defineINF 100000000inline ll read () {ll x=0, f=1; CharCh=GetChar (); while(ch<'0'|| Ch>'9') { if(ch=='-') f=-1; CH=GetChar (); } while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; CH=GetChar (); } returnx*F;}//****************************************#defineMAXN 10000+5intAA[MAXN],H[MAXN];CharA[MAXN],B[MAXN];voidDfsintXints) { if(x==0) {H[s+ the]++; return ; } DFS (x-1, s+1); DFS (x-1, S-1);}intMain () {intans=0; scanf ("%s%s", A, b); intLena=strlen (a); intlenb=strlen (b); for(intI=0; i<lena;i++){ if(a[i]=='+') ans++; Elseans--; } inttmp=0; intdb{0; for(intI=0; i<lenb;i++){ if(b[i]=='+') tmp++; Else if(b[i]=='-') tmp--; Elsebb++; }DoubleAnss;mem (H); if(bb==0){ if(tmp==ans) {Anss=1.0; } Elseanss=0; } Else{DFS (bb,tmp); intsum=1; for(intI=1; i<=bb;i++) sum*=2; Anss=h[ans+ the]*1.0/sum*1.0; } printf ("%.12f\n", ANSS); return 0;}
Code
Codeforces Round #272 (Div. 2) Dreamoon and WiFi violence