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 ...
随机推荐
- Kafka 温故(四):Kafka的安装
Step 1: 下载Kafka > tar -xzf kafka_2.9.2-0.8.1.1.tgz> cd kafka_2.9.2-0.8.1.1 Step 2: 启动服务Kafka用到 ...
- JSBinding+Bridge.NET:Inspector拖变量支持
之前的文档说了,JSB的设计是不允许gameObject上挂逻辑脚本的.原因很简单,在Js工程中根本就不存在C#形式的逻辑脚本,如果在Cs工程中挂上了,到了Js工程这边,直接Missing. 实际在使 ...
- es6笔记(1) 概要
什么是ES6 ECMAScript 6.0 (简称ES6) 是继ECMAScript 5.1以后的javascript 语言的下一代标准,在2015年6月份发布. 他的目标是使javascript语言 ...
- Docker学习笔记二 使用镜像
本文地址:https://www.cnblogs.com/veinyin/p/10408363.html Docker运行容器前,需本地存在对应镜像,若没有则Docker从镜像仓库下载该镜像. 镜 ...
- Div中嵌套一个div,怎么是里面的div居中?
盒子居中是在写样式中经常遇到的问题,在这里说个我经常使用的方法~ 利用绝对定位:
- Wordpress页脚
<?php /** * The template for displaying the footer */ ?> <?php if ( apply_filters( 'show_fl ...
- 转:存储之直连存储Dell Powervault MD 3000
存储之直连存储DellPowervault MD 3000 存储根据服务器类型可以分为:封闭系统的存储和开放系统的存储 1.封闭系统的存储:封闭系统主要指大型机,AS400等服务器 2.开放系统的存储 ...
- Linux ALSA声卡驱动之五:移动设备中的ALSA(ASoC)
转自http://blog.csdn.net/droidphone/article/details/7165482 1. ASoC的由来 ASoC--ALSA System on Chip ,是建立 ...
- 使用pt-table-checksum校验MySQL主从复制【转】
pt-table-checksum是一个基于MySQL数据库主从架构在线数据一致性校验工具.其工作原理在主库上运行, 通过对同步的表在主从段执行checksum, 从而判断数据是否一致.在校验完毕时, ...
- python格式化输出【转】
今天写代码时,需要统一化输出格式进行,一时想不起具体细节,用了最笨的方法,现在讲常见的方法进行一个总结. 一.格式化输出 1.整数的输出 直接使用'%d'代替可输入十进制数字: >>> ...