B. Dreamoon and WiFi

题目连接:

http://www.codeforces.com/contest/476/problem/B

Description

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:

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

++-+-

+-+-+

Sample Output

1.000000000000

Hint

题意

给你一个串s1,和一个串s2

然后s2中有一些问号,有0.5的概率是向左边,有0.5的概率是向右边走。

问你s2结束之后,恰好走到s1串走到的目的地的概率是多少。

题解:

数据范围很小,怎么做都行。

我是概率dp,dp[i][j]表示考虑到执行第二个串的第i位现在在j位置的概率是多少。

代码

#include<bits/stdc++.h>
using namespace std; double dp[100][100];
char s1[50],s2[50];
int main()
{
scanf("%s%s",s1+1,s2+1);
int level = 50;
int pos=50;
int len1 = strlen(s1+1);
for(int i=1;i<=len1;i++)
{
if(s1[i]=='+')pos++;
else pos--;
}
dp[0][level]=1;
for(int i=1;i<=len1;i++)
{
if(s2[i]=='+')for(int j=1;j<100;j++)
dp[i][j]=dp[i-1][j-1];
if(s2[i]=='-')for(int j=0;j<99;j++)
dp[i][j]=dp[i-1][j+1];
if(s2[i]=='?')for(int j=1;j<99;j++)
dp[i][j]=0.5*dp[i-1][j-1]+0.5*dp[i-1][j+1];
}
printf("%.12f\n",dp[len1][pos]);
}

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

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

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

    题目链接: http://www.codeforces.com/contest/476/problem/E E. Dreamoon and Strings time limit per test 1 ...

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

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

  4. Codeforces Round #272 (Div. 2) E. Dreamoon and Strings 动态规划

    E. Dreamoon and Strings 题目连接: http://www.codeforces.com/contest/476/problem/E Description Dreamoon h ...

  5. Codeforces Round #272 (Div. 2) D. Dreamoon and Sets 构造

    D. Dreamoon and Sets 题目连接: http://www.codeforces.com/contest/476/problem/D Description Dreamoon like ...

  6. Codeforces Round #272 (Div. 2) A. Dreamoon and Stairs 水题

    A. Dreamoon and Stairs 题目连接: http://www.codeforces.com/contest/476/problem/A Description Dreamoon wa ...

  7. Codeforces Round #272 (Div. 1) A. Dreamoon and Sums(数论)

    题目链接 Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occa ...

  8. Codeforces Round #272 (Div. 2)-C. Dreamoon and Sums

    http://codeforces.com/contest/476/problem/C C. Dreamoon and Sums time limit per test 1.5 seconds mem ...

  9. Codeforces Round #272 (Div. 2)-A. Dreamoon and Stairs

    http://codeforces.com/contest/476/problem/A A. Dreamoon and Stairs time limit per test 1 second memo ...

随机推荐

  1. bzoj千题计划293:bzoj3142: [Hnoi2013]数列

    http://www.lydsy.com/JudgeOnline/problem.php?id=3142 如果已知数列的差分数列a[1]~a[k-1] 那么这种差分方式对答案的贡献为 N-Σ a[i] ...

  2. <header><footer>引用

    示例:http://www.w3school.com.cn/html/html_layout.asp

  3. [BZOJ 1652][USACO 06FEB]Treats for the Cows 题解(区间DP)

    [BZOJ 1652][USACO 06FEB]Treats for the Cows Description FJ has purchased N (1 <= N <= 2000) yu ...

  4. 善用backtrace解决大问题【转】

    转自:https://www.2cto.com/kf/201107/97270.html 一.用途: 主要用于程序异常退出时寻找错误原因 二.功能: 回溯堆栈,简单的说就是可以列出当前函数调用关系 三 ...

  5. MVC 获取路由的 URL 参数值和默认值的集合。

    跟aspx页面不一样 用Request 获取不到路由配置的 参数 可以采用下面方法获取 public ActionResult List() { //获取路由中所有的key foreach (stri ...

  6. 六、vue路由Vue Router

    一.基本概念 route, routes, router 1, route,它是一条路由,由这个英文单词也可以看出来,它是单数, Home按钮  => home内容, 这是一条route,  a ...

  7. python与C交互中传入与读取内存空间

    使用用python调用c代码中,从外部传入一个固定大小的内存空间,这段内存需要是可写的 首先看下c中的函数 typedef struct ModelData { unsigned int model_ ...

  8. MVC Autofac依赖注入

    通过Dll实现全部类的属性注入,该演示实例主要通过多层架构中单一的对象方式来演示,没有采取接口的方式, 新建AutoFacHelper类,如下代码: public class AutoFacHelpe ...

  9. python基础--模块使用

      一:模块介绍 模块分为三种: 自定义模块 内置标准模块(又称标准库) 开源模块 自定义模块使用 # -*- coding:utf-8 -*- __author__ = 'shisanjun' &q ...

  10. vs2017 Remote Debugger远程调试目录

    默认目录:C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\Remote Debugger