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 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的更多相关文章
- 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) E. Dreamoon and Strings dp
题目链接: http://www.codeforces.com/contest/476/problem/E E. Dreamoon and Strings time limit per test 1 ...
- Codeforces Round #272 (Div. 2) B. Dreamoon and WiFi (暴力二进制枚举)
题意:给你一个只含\(+\)和\(-\)的字符串,统计它的加减和,然后再给你一个包含\(+,-,?\)的字符串,其中\(?\)可以表示为\(+\)或\(-\),问有多少种情况使得第二个字符串的加减和等 ...
- Codeforces Round #272 (Div. 2) E. Dreamoon and Strings 动态规划
E. Dreamoon and Strings 题目连接: http://www.codeforces.com/contest/476/problem/E Description Dreamoon h ...
- Codeforces Round #272 (Div. 2) D. Dreamoon and Sets 构造
D. Dreamoon and Sets 题目连接: http://www.codeforces.com/contest/476/problem/D Description Dreamoon like ...
- Codeforces Round #272 (Div. 2) A. Dreamoon and Stairs 水题
A. Dreamoon and Stairs 题目连接: http://www.codeforces.com/contest/476/problem/A Description Dreamoon wa ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- python学习笔记5--加密模块hashlib
import hashlib # md5 ybm_pwd='yuanbapqingsdfs234FF234HF@F' # m = hashlib.md5() # bytes_ybq = ybm_pwd ...
- 读书笔记:《思考的乐趣:Matrix67数学笔记》第4章 统计数据的陷阱
<思考的乐趣:Matrix67数学笔记>第4章讲了几个统计学上的陷阱,由于现在流行的大数据与统计学很有渊源,所以认真读了这一章,在<大数据时代>中指出只考虑相关性就够了,而不考 ...
- 【Python】如何基于Python写一个TCP反向连接后门
首发安全客 如何基于Python写一个TCP反向连接后门 https://www.anquanke.com/post/id/92401 0x0 介绍 在Linux系统做未授权测试,我们须准备一个安全的 ...
- springcloud中的负载均衡策略
IRule 这是所有负载均衡策略的父接口,里边的核心方法就是choose方法,用来选择一个服务实例. AbstractLoadBalancerRule AbstractLoadBalancerRule ...
- ps自由变换以及再次变换快捷键
ctrl+t:自由变换ctrl+shift+t:再次变换ctrl+shift+alt+t:复制一次,再次变换.
- LeetCode(10):正则表达式匹配
Hard! 题目描述: 给定一个字符串 (s) 和一个字符模式 (p).实现支持 '.' 和 '*' 的正则表达式匹配. '.' 匹配任意单个字符. '*' 匹配零个或多个前面的元素. 匹配应该覆盖整 ...
- kafka一直rebalance故障,重复消费
今天我司线上kafka消息代理出现错误日志,异常rebalance,而且平均间隔2到3分钟就会rebalance一次,分析日志发现比较严重.错误日志如下 08-09 11:01:11 131 pool ...
- Codeforces 405E Graph Cutting
Graph Cutting 不会写.. dfs的过程中把回边丢到它的祖先中去, 回溯的时候两两配对.感觉好神奇啊. #include<bits/stdc++.h> #define LL l ...
- 【Java】 大话数据结构(13) 查找算法(4) (散列表(哈希表))
本文根据<大话数据结构>一书,实现了Java版的一个简单的散列表(哈希表). 基本概念 对关键字key,将其值存放在f(key)的存储位置上.由此,在查找时不需比较,只需计算出f(key) ...
- 黑苹果 之 神舟战神Z7M-SL7D2
黑苹果引导工具 Clover 配置详解:http://www.jianshu.com/p/b156b0177a24 神舟Z7m UEFI+GPT安装WIN10+MAC OS X Yosemite双系统 ...