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. mysql in 方法查询 按照 in队列里的顺序排序

    String sql ' GROUP BY comm " + "order by field(comm,?,?,?,?,?,?,?,?)"; stmt = conn.pr ...

  2. 关于service和线程的区别

    主要有两方面,访问控制和功能区别 首先,service是运行在主线程上的,并不是一个新的线程 其次,service在运行的时候可以被多个activity访问和控制,而线程是不可以的 最后,servic ...

  3. 第4章_Java仿微信全栈高性能后台+移动客户端

    基于web端使用netty和websocket来做一个简单的聊天的小练习.实时通信有三种方式:Ajax轮询.Long pull.websocket,现在很多的业务场景,比方说聊天室.或者手机端onli ...

  4. mock SpringMVC 测试控制器方法

    从Spring3.2开始 Spring包含了一种mockSpringMVC并针对controller执行http请求的机制 如(该代码选自spring实战4): public void shouldS ...

  5. head first 设计模式 观察者模式

    Head first 设计模式:定义了对象之间的一对多依赖,这样一来,当一个对象改变状态时,它的所有依赖者都会受到通知并自动更新.   让主题与观察者之间松耦合 大话设计模式:定义了一种一对多的依赖关 ...

  6. linux ftp、sftp、telnet服务开通、更改Orale最大连接数

    1 ftp服务开通 1.1 检测vsftpd是否安装及启动 先用service vsftpd status 来查看ftp是否开启.也可以使用ps -ef | grep ftp 来查看本地是否含有包含f ...

  7. 【Java学习】Java泛型详解

    1. 概述 在引入范型之前,Java类型分为原始类型.复杂类型,其中复杂类型分为数组和类.引入范型后,一个复杂类型就可以在细分成更多的类型.例如原先的类型List,现在在细分成List<Obje ...

  8. How a web page loads

    The major web browsers load web pages in basically the same way. This process is known as parsing an ...

  9. SpringMVC路径问题回顾,加斜杠和不加斜杠的问题(六)

    绝对路径:全的路径. 相对路径:有参照的路径. 加斜杠和不加斜杠的问题如下:(分前台和后台路径,明白这两个就知道什么意思了) 如果是页面,这个图片路径出现在jsp页面,所以是前台路径,前台路径的参照物 ...

  10. vim尝试

    http://3502990.blog.51cto.com/3492990/985750