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

Copy
++-+-
+-+-+
output

Copy
1.000000000000
input

Copy
+-+-
+-??
output

Copy
0.500000000000
input

Copy
+++
??-
output

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


网上看了别人的想法,感觉思路清奇,DP数组处理的时候用了一点小技巧。

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <numeric>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define mod 998244353
using namespace std;
int dir[][] = { {,},{,-},{-,},{,} }; int main()
{
string s1, s2;
cin >> s1 >> s2;
int pos1=,pos2=,q=;
for (int i = ; i < s1.size(); i++)
{
if (s1[i] == '+')
pos1++;
else
pos1--;
if (s2[i] == '+')
pos2++;
else if (s2[i] == '-')
pos2--;
else
q++;
}
vector<vector<double>> dp(, vector<double>());
dp[][pos2+] = ;
int len = s1.size();
for (int i = ; i <= q; i++)
{
for (int j = -; j <= len; j++)
{
dp[i][j + ] = dp[i - ][j - + ] * 0.5 + dp[i - ][j + + ] * 0.5;
}
}
printf("%.10f", dp[q][pos1+]);
return ;
}

Dreamoon and WiFi的更多相关文章

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

  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. CodeForces - 476B -Dreamoon and WiFi(DFS+概率思维)

    Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands throug ...

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

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

  7. Codeforces Round #272 (Div. 2) B. Dreamoon and WiFi (暴力二进制枚举)

    题意:给你一个只含\(+\)和\(-\)的字符串,统计它的加减和,然后再给你一个包含\(+,-,?\)的字符串,其中\(?\)可以表示为\(+\)或\(-\),问有多少种情况使得第二个字符串的加减和等 ...

  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. 关于MySQL数据库中null的那些事

    在mysql数据库中,null是一个经常出现的情况,关于mysql中的null,有哪些注意事项呢?下面简单总结归纳下,后续会不断补充. 1. is null 首先判断数据库中某一列的值是否为null, ...

  2. 浅析Thread的join() 方法

    Thread中的 join() 方法在实际开发过程中可能用的不是很多,但是在面试中作为考察基本功知识的扎实与否,经常会被用到.因此,对于 Thread 的 join() 方法进行了一定的研究. 常见的 ...

  3. PAT (Advanced Level) Practice 1015 Reversible Primes (20 分)

    A reversible prime in any number system is a prime whose "reverse" in that number system i ...

  4. 指数函数在c语言实现

    指数很重要,比如有一些欧拉公式 #include "common.h" #include <stdio.h> #include <stdlib.h> #in ...

  5. SYZOJP186 你猜猜是不是DP 二分+hash解法

    SYZOJP186 你猜猜是不是DP题解 题目传送门 现在给两个仅包含小写字母的字符串a,b ,求a 与b的最长公共连续子串的长度. 对于20%的数据,a,b长度 ∈ [1, 200] 对于50%的数 ...

  6. VsCode开发Java SpringBoot遇到的问题

    报错截图 报错一:Build failed, Do you want to continue? 编译失败,你想继续吗? 报错二:ConfigError:The Project "Demo&q ...

  7. windows下安装配置subline+Markdown

    安装环境:win10 64bit 1. 安装subline3 subline : http://www.sublimetextcn.com/  直接下载安装,不用激活(dao版,慎用) 2. 安装Ma ...

  8. Python-Django学习笔记(一)-MTV设计模式

    Django是开源的.大而且全的Web应用框架. 它独具特色,采用了MTV设计模式. MTV框架包括:Model(模型).Template(模板)和View(视图) Model(模型):负责业务对象与 ...

  9. shell脚本执行sql命令

    参考:https://www.cnblogs.com/xingchong/p/11698237.html

  10. Coursera 吴恩达 机器学习 学习笔记

    Week 1 机器学习笔记(一)基本概念与单变量线性回归 Week 2   机器学习笔记(二)多元线性回归 机器学习作业(一)线性回归——Matlab实现 机器学习作业(一)线性回归——Python( ...