lonlifeOJ1152 “玲珑杯”ACM比赛 Round #19 概率DP
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.
#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的更多相关文章
- “玲珑杯”ACM比赛 Round #19题解&源码【A,规律,B,二分,C,牛顿迭代法,D,平衡树,E,概率dp】
A -- simple math problem Time Limit:2s Memory Limit:128MByte Submissions:1599Solved:270 SAMPLE INPUT ...
- “玲珑杯”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 ...
- 玲珑杯”ACM比赛 Round #19 B 维护单调栈
1149 - Buildings Time Limit:2s Memory Limit:128MByte Submissions:588Solved:151 DESCRIPTION There are ...
- “玲珑杯”ACM比赛 Round #19
A -- A simple math problem Time Limit:2s Memory Limit:128MByte Submissions:1599Solved:270 DESCRIPTIO ...
- “玲珑杯”ACM比赛 Round #12题解&源码
我能说我比较傻么!就只能做一道签到题,没办法,我就先写下A题的题解&源码吧,日后补上剩余题的题解&源码吧! A ...
- “玲珑杯”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 ...
- “玲珑杯”ACM比赛 Round #18
“玲珑杯”ACM比赛 Round #18 Start Time:2017-07-15 12:00:00 End Time:2017-07-15 15:46:00 A -- 计算几何你瞎暴力 Time ...
- “玲珑杯”ACM比赛 Round #4 E -- array DP
http://www.ifrog.cc/acm/problem/1050?contest=1006&no=4 DP[val]表示以val这个值结尾的等差数列有多少个 DP[val] += DP ...
- “玲珑杯”ACM比赛 Round #18 C -- 图论你先敲完模板(和题目一点关系都没有,dp)
题目链接:http://www.ifrog.cc/acm/problem/1146?contest=1020&no=2 题解:显然知道这是一道dp而且 dp[i]=min(dp[j]+2^(x ...
随机推荐
- [android开发篇]权限列表
http://www.open-open.com/lib/view/open1425868811607.html
- TOJ 4701 求阴影部分面积
4701: 求阴影部分面积 本文版权归BobHuang和博客园共有,不得转载.如想转载,请联系作者,并注明出处. Time Limit(Common/Java):1000MS/3000MS ...
- java第五章 子类与继承
5.1子类与父类 1 java不支持多重继承,即一个子类不可以从多个父类中同时继承,而C++中可以. 人们习惯地称子类与父类的关系式“is—a”的关系 2 再类的声明过程中,通过关键字exte ...
- 九度oj 题目1499:项目安排
题目描述: 小明每天都在开源社区上做项目,假设每天他都有很多项目可以选,其中每个项目都有一个开始时间和截止时间,假设做完每个项目后,拿到报酬都是不同的.由于小明马上就要硕士毕业了,面临着买房.买车.给 ...
- POJ 2359 Questions
Questions Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1228 Accepted: 449 Descript ...
- MySQL 待解决死锁
官方文档:https://dev.mysql.com/doc/refman/5.6/en/innodb-locks-set.html 线上出现一个死锁现象,信息显示的是两条对同一个表的不同记录的upd ...
- DDLog-不同颜色打印信息
(一)下载安装 1.安装插件 XcodeColors Github 链接:https://github.com/robbiehanson/XcodeColors 打开XcodeColors项目,编译即 ...
- 【Luogu】P1879玉米田(状压DP)
题目链接 数据范围这么小,难度又这么大,一般就是状态压缩DP了. 对输入进行处理,二进制表示每一行的草地状况.如111表示这一行草地肥沃,压缩成7. 所以f[i][j]表示第i行状态为j时的方案数 状 ...
- SPOJ LCS2 Longest Common Substring II ——后缀自动机
后缀自动机裸题 #include <cstdio> #include <cstring> #include <iostream> #include <algo ...
- 网上找的一篇博文,原文搞错了,应该是\r\n,本文已改正!——回车CR和换行line feed
"回车"(carriage return)和"换行"(line feed)与 ASCII表 关于“回车”(carriage return)和“换行”(line ...