E -- Expected value of the expression
DESCRIPTION

You are given an expression: A0O1A1O2A2⋯OnAnA0O1A1O2A2⋯OnAn, where Ai(0≤i≤n)Ai(0≤i≤n) represents number, Oi(1≤i≤n)Oi(1≤i≤n) represents operator. There are three operators, &,|,^&,|,^, which means and,or,xorand,or,xor, and they have the same priority.

The ii-th operator OiOi and the numbers AiAi disappear with the probability of pipi.

Find the expected value of an expression.

INPUT
The first line contains only one integer n(1≤n≤1000)n(1≤n≤1000). The second line contains n+1n+1 integers Ai(0≤Ai<220)Ai(0≤Ai<220). The third line contains nn chars OiOi. The fourth line contains nn floats pi(0≤pi≤1)pi(0≤pi≤1).
OUTPUT
Output the excepted value of the expression, round to 6 decimal places.
SAMPLE INPUT
2
1 2 3
^ &
0.1 0.2
SAMPLE OUTPUT
2.800000
HINT
Probability = 0.1 * 0.2 Value = 1 Probability = 0.1 * 0.8 Value = 1 & 3 = 1 Probability = 0.9 * 0.2 Value = 1 ^ 2 = 3 Probability = 0.9 * 0.8 Value = 1 ^ 2 & 3 = 3 Expected Value = 0.1 * 0.2 * 1 + 0.1 * 0.8 * 1 + 0.9 * 0.2 * 3 + 0.9 * 0.8 * 3 = 2.80000
 
 
题意:
  给你一个n+1个数进行位操作
  给你这个n+1个数(a0~an)和 进行的操作(异或,并,或) c[i]
  ci 和 ai同时消失的 概率是 pi
  求最后值得期望
题解:
  dp[i][25][0/1]
  表示前i个 数  0~21位上每一位存在(0/1)的概率,强推过去就行了
#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define mid ((ll+rr)>>1)
#define pii pair<int,int>
#define MP make_pair
typedef long long LL;
const long long INF = 1e18+1LL;
const double pi = acos(-1.0);
const int N = 5e3+, M = 1e3+,inf = 2e9; int n,a[N];
char c[N];
double dp[N][][],p[N];
int main() {
while(scanf("%d",&n)!=EOF) {
for(int i = ; i <= n; ++i) {
scanf("%d",&a[i]);
}
memset(dp,,sizeof(dp));
for(int i = ; i <= n; ++i) {
getchar();
scanf("%c",&c[i]);
}
for(int i = ; i <= n; ++i) {
scanf("%lf",&p[i]);
}
for(int i = ; i <= ; ++i) {
if(((<<i)&a[])) dp[][i][] = ,dp[][i][] = ;
else dp[][i][] = ,dp[][i][] = ;
}
for(int i = ; i <= n; ++i) { for(int j = ; j <= ; ++j) {
dp[i][j][] += 1.0*dp[i-][j][] * p[i];
dp[i][j][] += 1.0*dp[i-][j][] * p[i];
}
for(int j = ; j <= ; ++j) {
int tmp = ((a[i]>>j)&);
if(c[i] == '^') {
dp[i][j][tmp^] += 1.0*dp[i-][j][]*(1.0-p[i]);
dp[i][j][tmp^] += 1.0*dp[i-][j][]*(1.0-p[i]);
}
else if(c[i] == '&'){
dp[i][j][tmp&] += 1.0*dp[i-][j][]*(1.0-p[i]);
dp[i][j][tmp&] += 1.0*dp[i-][j][]*(1.0-p[i]);
}
else if(c[i] == '|') {
dp[i][j][tmp|] += 1.0*dp[i-][j][]*(1.0-p[i]);
dp[i][j][tmp|] += 1.0*dp[i-][j][]*(1.0-p[i]);
}
}
}
double ans = ;
for(int i = ; i <= ; ++i) {
LL tmp = <<i;
ans += (double)(dp[n][i][]) * 1.0 * tmp;
}
printf("%.6f\n",ans);
}
return ;
}

lonlifeOJ1152 “玲珑杯”ACM比赛 Round #19 概率DP的更多相关文章

  1. “玲珑杯”ACM比赛 Round #19题解&源码【A,规律,B,二分,C,牛顿迭代法,D,平衡树,E,概率dp】

    A -- simple math problem Time Limit:2s Memory Limit:128MByte Submissions:1599Solved:270 SAMPLE INPUT ...

  2. “玲珑杯”ACM比赛 Round #19 B -- Buildings (RMQ + 二分)

    “玲珑杯”ACM比赛 Round #19 Start Time:2017-07-29 14:00:00 End Time:2017-07-29 16:30:00 Refresh Time:2017-0 ...

  3. 玲珑杯”ACM比赛 Round #19 B 维护单调栈

    1149 - Buildings Time Limit:2s Memory Limit:128MByte Submissions:588Solved:151 DESCRIPTION There are ...

  4. “玲珑杯”ACM比赛 Round #19

    A -- A simple math problem Time Limit:2s Memory Limit:128MByte Submissions:1599Solved:270 DESCRIPTIO ...

  5. “玲珑杯”ACM比赛 Round #12题解&源码

    我能说我比较傻么!就只能做一道签到题,没办法,我就先写下A题的题解&源码吧,日后补上剩余题的题解&源码吧!                                     A ...

  6. “玲珑杯”ACM比赛 Round #1

    Start Time:2016-08-20 13:00:00 End Time:2016-08-20 18:00:00 Refresh Time:2017-11-12 19:51:52 Public ...

  7. “玲珑杯”ACM比赛 Round #18

    “玲珑杯”ACM比赛 Round #18 Start Time:2017-07-15 12:00:00 End Time:2017-07-15 15:46:00 A -- 计算几何你瞎暴力 Time ...

  8. “玲珑杯”ACM比赛 Round #4 E -- array DP

    http://www.ifrog.cc/acm/problem/1050?contest=1006&no=4 DP[val]表示以val这个值结尾的等差数列有多少个 DP[val] += DP ...

  9. “玲珑杯”ACM比赛 Round #18 C -- 图论你先敲完模板(和题目一点关系都没有,dp)

    题目链接:http://www.ifrog.cc/acm/problem/1146?contest=1020&no=2 题解:显然知道这是一道dp而且 dp[i]=min(dp[j]+2^(x ...

随机推荐

  1. [android开发篇]权限列表

    http://www.open-open.com/lib/view/open1425868811607.html

  2. TOJ 4701 求阴影部分面积

    4701: 求阴影部分面积  本文版权归BobHuang和博客园共有,不得转载.如想转载,请联系作者,并注明出处. Time Limit(Common/Java):1000MS/3000MS     ...

  3. java第五章 子类与继承

    5.1子类与父类 1   java不支持多重继承,即一个子类不可以从多个父类中同时继承,而C++中可以. 人们习惯地称子类与父类的关系式“is—a”的关系 2   再类的声明过程中,通过关键字exte ...

  4. 九度oj 题目1499:项目安排

    题目描述: 小明每天都在开源社区上做项目,假设每天他都有很多项目可以选,其中每个项目都有一个开始时间和截止时间,假设做完每个项目后,拿到报酬都是不同的.由于小明马上就要硕士毕业了,面临着买房.买车.给 ...

  5. POJ 2359 Questions

    Questions Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1228   Accepted: 449 Descript ...

  6. MySQL 待解决死锁

    官方文档:https://dev.mysql.com/doc/refman/5.6/en/innodb-locks-set.html 线上出现一个死锁现象,信息显示的是两条对同一个表的不同记录的upd ...

  7. DDLog-不同颜色打印信息

    (一)下载安装 1.安装插件 XcodeColors Github 链接:https://github.com/robbiehanson/XcodeColors 打开XcodeColors项目,编译即 ...

  8. 【Luogu】P1879玉米田(状压DP)

    题目链接 数据范围这么小,难度又这么大,一般就是状态压缩DP了. 对输入进行处理,二进制表示每一行的草地状况.如111表示这一行草地肥沃,压缩成7. 所以f[i][j]表示第i行状态为j时的方案数 状 ...

  9. SPOJ LCS2 Longest Common Substring II ——后缀自动机

    后缀自动机裸题 #include <cstdio> #include <cstring> #include <iostream> #include <algo ...

  10. 网上找的一篇博文,原文搞错了,应该是\r\n,本文已改正!——回车CR和换行line feed

    "回车"(carriage return)和"换行"(line feed)与 ASCII表 关于“回车”(carriage return)和“换行”(line  ...