Dreamoon and WiFi ???下同一位置的概率
来源:互联网 发布:mac怎么设置屏幕 编辑:程序博客网 时间:2024/05/16 18:39
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.
题目意思:http://codeforces.com/contest/476/problem/B
初始在0的位置,+往右移动1,-往左移动1,一个串s之后会停止某个位置。另外,输入一个串str,存在?,问最后在同一个位置的概率是多少。
dfs把2^cnt全部搜出来,暴力计数就行了。
#include<iostream>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>#include<vector>#include<queue>#include<map>#include<stack>#define rt return#define bk break#define ct continue#define sf scanf#define pf printf#define ms memset#define si(n) sf("%d",&n)#define pi(n) pf("%d\n",n)#define REP0(i,n) for(int i=0;i<(n);i++)#define REP1(i,n) for(int i=1;i<=(n);i++)#define REP(i,s,n) for(int i=s;i<=(n);i++)#define db double#define op operator#define pb push_back#define LL long long#define INF 0x3fffffff#define eps 1e-8#define PI acos(-1)#define maxn 1010using namespace std;int res;void dfs(char s[],int cnt,int ans1,int ans2){ if(cnt==ans1+ans2){ int tmp1=0,tmp2=0; for(int i=0;i<cnt;i++) if(s[i]=='+')tmp1++; else tmp2++; if(tmp1==ans1&&tmp2==ans2) res++; rt ; } s[cnt]='+'; dfs(s,cnt+1,ans1,ans2); s[cnt]='-'; dfs(s,cnt+1,ans1,ans2);}int main(){ #ifdef ACBang freopen("in.txt","r",stdin); #endif char s1[20],s2[20]; while(~sf("%s%s",s1,s2)){ int cnt1=0,cnt2=0; int ans1=0,ans2=0,ans=0; int len=strlen(s1); for(int i=0;i<len;i++){ if(s1[i]=='+')cnt1++; else cnt2++; if(s2[i]=='+')ans1++; else if(s2[i]=='-')ans2++; else ans++; } //if(cnt1<ans1||cnt2<ans2)puts("0.000000000000"); //else{ ans1=cnt1-ans1; ans2=cnt2-ans2; res=0; char s[20]; dfs(s,0,ans1,ans2); pf("%.12lf\n",res*1.0/pow(2.0,1.0*(ans1+ans2))); //} } rt 0;}
- Dreamoon and WiFi ???下同一位置的概率
- codeforces B. Dreamoon and WiFi 组合数学求概率
- CodeForces 476B Dreamoon and WiFi 数学 概率 DP
- B. Dreamoon and WiFi
- Dreamoon and WiFi
- Dreamoon and WiFi
- 【CODEFORCES】 B. Dreamoon and WiFi
- CF 272B Dreamoon and WiFi
- B. Dreamoon and WiFi(Codeforces Round 272)
- Codeforces 476B. Dreamoon and WiFi
- Codeforces 476B Dreamoon and WiFi
- F - Dreamoon and WiFi 组合数学
- Dreamoon and WiFi CodeForces - 476B
- Codeforces Round #272 (Div. 2) B. Dreamoon and WiFi 暴力
- Codeforces Round #272 (Div. 2)B. Dreamoon and WiFi
- codeforces-#476B. Dreamoon and WiFi(dfs、二进制枚举)
- 【CodeForces 476B】 Dreamoon and WiFi(组合概率)
- Dreamoon and Stairs上台阶
- C++中虚函数工作原理和(虚)继承类的内存占用大小计算
- Codeforces Round #272 (Div. 2) D
- 第一章学习总结
- 思维导图——数据结构
- PHP的静态成员以及self、$this和parent三者的区别
- Dreamoon and WiFi ???下同一位置的概率
- Ubuntu安装jdk
- 正则表达式相关
- 第一章知识结构导图(原来浏览器无法上传)
- 3D 打印 printbot 教程集合
- 解释BOM头和去掉方法
- Codeforces Round #272 (Div. 1)B(构造)
- 手机耳机接口标准
- nyoj-768-移位密码