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+10, M = 1e3+20,inf = 2e9;int n,a[N];
char c[N];
double dp[N][30][2],p[N];
int main() {while(scanf("%d",&n)!=EOF) {for(int i = 0; i <= n; ++i) {scanf("%d",&a[i]);}memset(dp,0,sizeof(dp));for(int i = 1; i <= n; ++i) {getchar();scanf("%c",&c[i]);}for(int i = 1; i <= n; ++i) {scanf("%lf",&p[i]);}for(int i = 0; i <= 21; ++i) {if(((1<<i)&a[0])) dp[0][i][1] = 1,dp[0][i][0] = 0;else dp[0][i][0] = 1,dp[0][i][1] = 0;}for(int i = 1; i <= n; ++i) {for(int j = 0; j <= 21; ++j) {dp[i][j][1] += 1.0*dp[i-1][j][1] * p[i];dp[i][j][0] += 1.0*dp[i-1][j][0] * p[i];}for(int j = 0; j <= 21; ++j) {int tmp = ((a[i]>>j)&1);if(c[i] == '^') {dp[i][j][tmp^1] += 1.0*dp[i-1][j][1]*(1.0-p[i]);dp[i][j][tmp^0] += 1.0*dp[i-1][j][0]*(1.0-p[i]);}else if(c[i] == '&'){dp[i][j][tmp&1] += 1.0*dp[i-1][j][1]*(1.0-p[i]);dp[i][j][tmp&0] += 1.0*dp[i-1][j][0]*(1.0-p[i]);}else if(c[i] == '|') {dp[i][j][tmp|1] += 1.0*dp[i-1][j][1]*(1.0-p[i]);dp[i][j][tmp|0] += 1.0*dp[i-1][j][0]*(1.0-p[i]);}}}double ans = 0;for(int i = 0; i <= 21; ++i) {LL tmp = 1<<i;ans += (double)(dp[n][i][1]) * 1.0 * tmp;}printf("%.6f\n",ans);}return 0;
}

转载于:https://www.cnblogs.com/zxhl/p/7256376.html

lonlifeOJ1152 “玲珑杯”ACM比赛 Round #19 概率DP相关推荐

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

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

  2. “玲珑杯”ACM比赛 Round #18 C -- 图论你先敲完模板【Dp】

    C -- 图论你先敲完模板 Time Limit:5s Memory Limit:256MByte Submissions:660Solved:160 DESCRIPTION 今天HHHH在操场上跑步 ...

  3. “玲珑杯”ACM比赛 Round #21-C-战舰萝莉(线段树区间更新)

    "玲珑杯"ACM比赛 Round #21 Start Time:2017-09-23 17:00:00 End Time:2017-09-23 19:30:00 Refresh T ...

  4. “玲珑杯”ACM比赛 Round #18 ABC题解

    A -- 计算几何你瞎暴力 Time Limit:5s Memory Limit:256MByte Submissions:1597Solved:301 DESCRIPTION 今天HHHH考完了期末 ...

  5. 玲珑杯”ACM比赛 Round #15 D 咸鱼商店【二分+01背包】

    题目链接:http://www.ifrog.cc/acm/problem/1125 题目大意:中文题目,题意请仔细看题面. 解题思路:二分+01背包     01背包的最终结果与其中的顺序无关,我们要 ...

  6. 玲珑杯”ACM比赛 Round #8-D XJT Loves Boggle(dfs)

    记录一个菜逼的成长.. DESCRIPTION Boggle is a word game designed by Allan Turoff and distributed by Hasbro. It ...

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

    运气不错有个抱枕. 1046 - chess play 题意: 一个n*m的数组,初始全部是'.',然后3种操作,把一个位置变成'w',或者把一个位置变成'r',或者交换两行. 思路: vector的 ...

  8. “玲珑杯”ACM比赛 Round #22 E【贪心】

    题目: http://www.ifrog.cc/acm/problem/1171?contest=1024&no=4 题意: 输入一个字符串,将他重新排列,使得重排之后的字符串的最小表示法,最 ...

  9. “玲珑杯”ACM比赛 Round #24: C. この戦いが終わったら(BFS+bitset优化暴力)

    C -- この戦いが終わったら 给你一个无向图,每次查询的时候给一堆二元组(xi,yi) 求图中有多少个点u与至少一个这次询问给出的二元组(xi,yi)满足dist(u,xi)<=yi,dist ...

最新文章

  1. 返回txt格式的文本使用编码 js_Node.js学习笔记第一天
  2. Algorithm Course Review(7.1)
  3. html中怎样播放本地视频教程,【Axure9基础教程】内联框架如何引入本地音频 视频 HTML PDF等本地文件...
  4. 用正则表达式输出rdf文档的三元组格式数据
  5. AI Challenger全球AI挑战赛开幕,300万奖金池,还可能获李开复投资
  6. 大数据BI系统如何做数据采集
  7. java亚马逊模拟登录_java – 亚马逊MWS入门
  8. 责任分配矩阵和raci的区别_有限责任公司实现盈利,当年就一定可以分红吗?...
  9. redis---队列的操作
  10. python入门到精通,一篇就够。40个python游戏经典开源项目(开源分享:俄罗斯方块、魂斗罗、植物大战僵尸、飞机大战、超级玛丽...)
  11. oppoR9s计算机使用方法,oppor9s怎么进入Recovery模式
  12. C语言输入某年某月某日,判断这一天是这一年的第几天(含判断闰年)
  13. JavaWeb企业在线文档管理系统
  14. QT开源网站和相关资料
  15. amap高德地图应用(el-amap-marker坐标点;el-amap-info-window信息窗体;el-amap-polyline折线、折线颜色,宽度、实虚线等)
  16. 福利,架构师之路定制T恤
  17. 串口转以太网服务器原理,串口服务器和串口转以太网模块的区别
  18. Java代码控制UI界面
  19. idea 重新拉maven依赖
  20. Netty里面的Boss和Worker【Server篇】

热门文章

  1. getset原子性 redis_RedisAPI原子性操作及原理解析
  2. go web框架_干货分享:六个知名的Go语言web框架
  3. srand和rand函数_了解C ++ rand()和srand()函数
  4. python sys模块_Python sys模块
  5. 不要运行explorer_在Internet Explorer浏览器上运行测试
  6. c ++创建二维数组_C ++中的二维数组
  7. 软件系统架构有哪几种?
  8. C语言基础教程之enum
  9. OpenCV(一)Mac下OpenCV的安装和配置
  10. 自定义可拖拽GridView控件