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 two types:

  1. Go 1 unit towards the positive direction, denoted as '+'
  2. 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 Dreamoon 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 an original list of commands sent by Drazil and list received by Dreamoon. What is the probability that Dreamoon ends in the position originally supposed to be final by Drazil's commands?

Input

The first line contains a string s1 — the commands Drazil sends to Dreamoon, this string consists of only the characters in the set {'+', '-'}.

The second line contains a string s2 — the commands Dreamoon's smartphone recognizes, this string consists of only the characters in the set {'+', '-', '?'}. '?' denotes an unrecognized command.

Lengths of two strings are equal and do not exceed 10.

Output

Output a single real number corresponding to the probability. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 9.

Examples

Input

++-+-
+-+-+

Output

1.000000000000

Input

+-+-
+-??

Output

0.500000000000

Input

+++
??-

Output

0.000000000000

Note

For the first sample, both s1 and s2 will lead Dreamoon to finish at the same position  + 1.

For the second sample, s1 will lead Dreamoon to finish at position 0, while there are four possibilites for s2: {"+-++", "+-+-", "+--+", "+---"} 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 lead us to finish at positions {+1, -1, -3}, so the probability to finish at the correct position  + 3 is 0.

思路:将?号部分进行dfs暴搜,然后去比较是否相等和sum1相等,相等s就加1,每次有问号会产生2的问号个数次方的情况,最后进行概率的转化即可

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath> using namespace std;
int sum1=0;
int sum2=0;
int sum3=0;
int s=0;
void dfs(int s1,int x)
{ if(s1==0)
{
if(x==sum1)
s++;
return ;
} dfs(s1-1,x+1);
dfs(s1-1,x-1); }
int main()
{ string str1,str2;
cin>>str1>>str2; for(int t=0;t<str1.length();t++)
{
if(str1[t]=='+')
{
sum1+=1;
}
if(str1[t]=='-')
{
sum1--;
}
}
for(int t=0;t<str2.length();t++)
{
if(str2[t]=='+')
{
sum2++;
}
if(str2[t]=='-')
{
sum2--;
}
if(str2[t]=='?')
{
sum3++;
}
}
int k=sum3;
if(sum3==0)
{
if(sum2==sum1)
{
printf("1.000000000000\n");
}
else
{
printf("0.000000000000\n");
}
}
else
{
dfs(sum3,sum2);
double ss=s*1.0/pow(2,k);
printf("%.12f\n",ss);
} return 0;
}

CodeForces - 476B -Dreamoon and WiFi(DFS+概率思维)的更多相关文章

  1. codeforces 476B.Dreamoon and WiFi 解题报告

    题目链接:http://codeforces.com/problemset/problem/476/B 题目意思:给出两个字符串str1, str2,其中,str1 只由 '+' 和 '-' 组成,而 ...

  2. Codeforces Round #272 (Div. 2) B. Dreamoon and WiFi dp

    B. Dreamoon and WiFi 题目连接: http://www.codeforces.com/contest/476/problem/B Description Dreamoon is s ...

  3. Codeforces Round #272 (Div. 2)-B. Dreamoon and WiFi

    http://codeforces.com/contest/476/problem/B B. Dreamoon and WiFi time limit per test 1 second memory ...

  4. Codeforces Round #272 (Div. 2) Dreamoon and WiFi 暴力

    B. Dreamoon and WiFi Dreamoon is standing at the position 0 on a number line. Drazil is sending a li ...

  5. B. Dreamoon and WiFi(Codeforces Round 272)

    B. Dreamoon and WiFi time limit per test 1 second memory limit per test 256 megabytes input standard ...

  6. DFS/BFS+思维 HDOJ 5325 Crazy Bobo

    题目传送门 /* 题意:给一个树,节点上有权值,问最多能找出多少个点满足在树上是连通的并且按照权值排序后相邻的点 在树上的路径权值都小于这两个点 DFS/BFS+思维:按照权值的大小,从小的到大的连有 ...

  7. Codeforces Round #546 (Div. 2) D 贪心 + 思维

    https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...

  8. codeforces 615 B. Longtail Hedgehog (DFS + 剪枝)

    题目链接: codeforces 615 B. Longtail Hedgehog (DFS + 剪枝) 题目描述: 给定n个点m条无向边的图,设一条节点递增的链末尾节点为u,链上点的个数为P,则该链 ...

  9. Codeforces 931D Peculiar apple-tree(dfs+思维)

    题目链接:http://codeforces.com/contest/931/problem/D 题目大意:给你一颗树,每个节点都会长苹果,然后每一秒钟,苹果往下滚一个.两个两个会抵消苹果.问最后在根 ...

随机推荐

  1. 常见浏览器bug以及解决方法

    1.图片下方3像素: (1).描述:在div中插入图片时,图片会将div下方撑大三像素. (2).hack1:将</div>与<img>写在一行上(可以解决ie6/7): (3 ...

  2. chromium浏览器开发系列第二篇:如何编译最新chromium

    说一下为什么这么晚才发第二篇,上周和这周department的工作太多了,晚上都是十点半从公司出发,回家以后实在没有多余的精力去摸键盘了.所以请大家包涵! 上期回顾: chromium源码下载: 1. ...

  3. python中注释的书写

    与c和c++的//不同的是,在python中我们使用#来进行注释 每个#所在的那一行都可以叫做注释:

  4. 字符串解压缩类库(zip、GZIP、QuickLz、snappy、lzf、jzlib)介绍

    1.ZIP. GZIP  计算机文件压缩算法,JDK中java.util.zip.*中实现.主要包括ZipInputStream/ ZipOutputStream.GZipInputStream/Zi ...

  5. springmvc 中异常处理

    springmvc 中异常处理常见三种处理方式: 1:SimpleMappingExceptionResolver处理的是处理器方法里面出现的异常 2 3.自定义异常处理器:处理的是处理器方法里面出现 ...

  6. actionbar中添加searchview并监听期伸缩/打开的方法

    首先在xml中设置actionviewclass <item android:id="@+id/m1" android:title="setting" a ...

  7. ROS探索总结(六)——使用smartcar进行仿真

    转自:https://www.ncnynl.com/archives/201609/843.html 总结: 一.机器人描述文件三个: 机器人主体body文件: gazebo属性文件: 主文件 sma ...

  8. 将字符串str1复制为字符串str2的三种方法

    1.自己编写函数,将两个字符串进行复制 #include<iostream> using namespace std; int main(){ char str1[]="I lo ...

  9. left join和right join、inner join 区别

    left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录  right join(右联接) 返回包括右表中的所有记录和左表中联结字段相等的记录 inner join(等值连接) ...

  10. win8使用every'thing无法显示搜索结果的解决方法

    关键词: win8,everything,无搜索结果 进入everything ,tools->option右下角有个 restore defaults 如果安全软件阻拦,点击  允许 就行了, ...