B. Dreamoon and WiFi
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Sample test(s)
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推断一遍即可了。

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char s1[20],s2[20];
int acou=0,dao=0,sum=0;
int n1,n2;
void solve(int n,int at)
{
if(n==n2)
{
if(at==acou)
dao++;
sum++;
return;
}
if(s2[n]=='+')
solve(n+1,at+1);
else if(s2[n]=='-')
solve(n+1,at-1);
else
{
solve(n+1,at+1);
solve(n+1,at-1);
}
} int main()
{
scanf("%s",s1);
scanf("%s",s2);
n1=strlen(s1);
n2=strlen(s2);
for(int i=0;i<n1;i++)
if(s1[i]=='+')
acou++;
else
acou--;
solve(0,0);
printf("%.12f\n",(double)(dao)/(sum));
return 0;
}

B. Dreamoon and WiFi(Codeforces Round 272)的更多相关文章

  1. A. Dreamoon and Stairs(Codeforces Round #272)

    A. Dreamoon and Stairs time limit per test 1 second memory limit per test 256 megabytes input standa ...

  2. E. Dreamoon and Strings(Codeforces Round #272)

    E. Dreamoon and Strings time limit per test 1 second memory limit per test 256 megabytes input stand ...

  3. D. Dreamoon and Sets(Codeforces Round #272)

    D. Dreamoon and Sets time limit per test 1 second memory limit per test 256 megabytes input standard ...

  4. Codeforces Round #272 (Div. 2) 题解

    Codeforces Round #272 (Div. 2) A. Dreamoon and Stairs time limit per test 1 second memory limit per ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. Codeforces Round #272 (Div. 2)

    A. Dreamoon and Stairs 题意:给出n层楼梯,m,一次能够上1层或者2层楼梯,问在所有的上楼需要的步数中是否存在m的倍数 找出范围,即为最大步数为n(一次上一级),最小步数为n/2 ...

  9. Codeforces Round #272 (Div. 2)AK报告

    A. Dreamoon and Stairs time limit per test 1 second memory limit per test 256 megabytes input standa ...

随机推荐

  1. 黑马程序员:Java基础总结----泛型(高级)

    黑马程序员:Java基础总结 泛型(高级)   ASP.Net+Android+IO开发 . .Net培训 .期待与您交流! 泛型(高级) 泛型是提供给javac编译器使用的,可以限定集合中的输入类型 ...

  2. BZOJ 刷题记录 PART 6

    [BZOJ2709]水的二分加验证.可是好像被读入萎到了... [BZOJ3229]强大的算法见此.被机房的一堆大神"推荐".于是被坑了...写了一个下午... [BZOJ3631 ...

  3. jsoncpp使用

    第一个github网站下载jsoncpp最新的版本库:https://github.com/open-source-parsers/jsoncpp 点击右下角的Download ZIP进行下载 解压后 ...

  4. LVS的调度算法分析

    LVS调度算法 一.静态调度算法 1.  rr(round robin)轮询调度,即调度器将客户端的请求依次的传递给内部的服务器,从1到N,算法简洁,无须记录状态,但是不考虑每台服务器的性能. 配置如 ...

  5. sd nfrmtl

    http://www.zhihu.com/collection/24337307 http://www.zhihu.com/collection/24337259 http://www.zhihu.c ...

  6. BZOJ 3112 Zjoi2013 防守战线 单纯形

    题目大意: 单纯形*2.. . #include <cmath> #include <cstdio> #include <cstring> #include < ...

  7. 安装 MYSQL exec: g++: not found 报错

    解决办法:   yum install -y gcc-c++

  8. coding.net解决github上下载速度慢问题

    由 于众所周知的原因,从github下载项目很慢,一般不超过10kb(我的是20兆公司网)例如我下载OpenRefine,没有3个小时搞不定.所以想 到了一个方法来解决他.就是使用国内其他代码托管平台 ...

  9. 京东商城招聘自动调价系统架构师 T4级别

    岗位级别:T4 岗位职责: 1.负责自动调价系统的架构设计 2.负责自动调价的预测.相关性算法设计 3.核心代码编写,代码review 任职要求: 1.熟悉数据挖掘.机器学习理论和算法 2.熟悉海量数 ...

  10. 【转】真正的Acmer

    上海交大 戴文渊 大牛写的东西,建议大家看看 yiyiyi4321 2007-07-10 13:49:30.0 http://dwyak.spaces.live.com/?_c11_BlogPart_ ...