Dreamoon and WiFi
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?
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 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.
++-+-
+-+-+
1.000000000000
+-+-
+-??
0.500000000000
+++
??-
0.000000000000
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的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- codeforces 476B.Dreamoon and WiFi 解题报告
题目链接:http://codeforces.com/problemset/problem/476/B 题目意思:给出两个字符串str1, str2,其中,str1 只由 '+' 和 '-' 组成,而 ...
- Codeforces Round #272 (Div. 2) B. Dreamoon and WiFi (暴力二进制枚举)
题意:给你一个只含\(+\)和\(-\)的字符串,统计它的加减和,然后再给你一个包含\(+,-,?\)的字符串,其中\(?\)可以表示为\(+\)或\(-\),问有多少种情况使得第二个字符串的加减和等 ...
- Codeforces Round #272 (Div. 2)
A. Dreamoon and Stairs 题意:给出n层楼梯,m,一次能够上1层或者2层楼梯,问在所有的上楼需要的步数中是否存在m的倍数 找出范围,即为最大步数为n(一次上一级),最小步数为n/2 ...
- Codeforces Round #272 (Div. 2)AK报告
A. Dreamoon and Stairs time limit per test 1 second memory limit per test 256 megabytes input standa ...
随机推荐
- 学习django3过程中的坑
最近跟着Django by Example 2015学习,可老想用最新版的Django3.在学的过程中可踩了不少坑. 今天就又碰到一个: 在这本书中96页有这样的代码: url(r'^login/$' ...
- LOJ#508. 「LibreOJ NOI Round #1」失控的未来交通工具
题意 一个带边权无向图,有两种操作:加边以及询问在\(x,x+b,...,x+(c-1)b\)这些数中,有多少个数存在至少一条与之模\(m\)同余的从\(u\)到\(v\)的路径(可以不是简单路径). ...
- 安装DHCP到CentOS(YUM)
运行环境 系统版本:CentOS Linux release 7.3.1611 (Core) 软件版本:DHCP-x 硬件要求:无 安装过程 1.安装YUM源,由EPEL提供 [root@localh ...
- H5_0013:CSS特色样式集
按比例变化,同时又限制最大宽高 ".start-wrap {", " width:40%;", " top: 83.21%;", " ...
- HTML与W3C
HTML:超文本标记语言 超文本包括:文字.图片.音频.视频.动画等 流程:写好HTML代码后通过浏览器(自动编译HTML代码)展现出效果 HTML优点: 世界知名浏览器厂商对HTML5的支持 微软 ...
- @Configuration@Bean
https://blog.csdn.net/u014199143/article/details/80692685 @Configuation等价于<Beans></Beans> ...
- Vue前端挂载对象时一些思考
最近,在Vue前端调试http请求,无论如何如何也是拦截不了某些http请求.场景是这样的:Java后端组装好Vue对象,然后送到前端,前端通过id来挂载该Vue对象,而该对象中有上传文件或者图片的控 ...
- [Python]pyhon去除txt文件重复行 python 2020.2.10
代码如下: import shutil readPath='E:/word4.txt' #要处理的文件 writePath='E:/word5.txt' #要写入的文件 lines_seen=set( ...
- LaTeX技巧007:每一章开始的header引用名言应该怎么做?
[问题描述] 看到很多论文的每一章开始的右上角都有一段名人名言, 我试验了很多次一直都搞不清楚是怎么搞?是用fancyhead么?谁可以说说呢? 多谢了 [解决方案] 使用epigraph宏包来制作即 ...
- 虚拟机中的CentOS 7设置固定IP连接最理想的配置(转载)
来源:虚拟机中的CentOS 7设置固定IP连接最理想的配置(https://my.oschina.net/panhongju/blog/826814) 转载说明:这是我看了很多篇虚拟机静态IP配置写 ...