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 ...
随机推荐
- 树状数组 Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains
C. Fountains time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- hdu2022
#include <stdio.h> #include <math.h> #define here puts("go,go,go!\n") int main ...
- javascript前端下载
<html> <head> <title>测试标题</title> </head> <body> <div> 测试页 ...
- Python2.6.6升级2.7.3
Python2.7替换2.6: 1.下载Python-2.7.3 #wget http://python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2 2.解压 ...
- Docker镜像分层技术
Docker镜像管理 1.镜像分层技术 2.创建镜像 3.下载镜像到主机 4.删除镜像 5.上传镜像到registry docker镜像: 早在集装箱没有出现的时候,码头上还有许多搬运的工人在搬运货物 ...
- leetcode 347 priority,map的使用
主要是对次数进行排序,然后去前几个最大次数的值,输出即可 class Solution { public: vector<int> topKFrequent(vector<int&g ...
- Yii 之cookie的使用
public function actionIndex(){ //设置cookie(注意这里用的是响应组件) $cookies = \YII::$app->response->cookie ...
- Post Content_Length exceeds the limit
2017.12,公司市场专员反馈我在公司开发与维护的iOS包内审系统在上传ipa包文件的时候报错了.经过调试发现原来是因为上传的文件太大导致报错(由下图可知,接收方允许的最大请求内容为128M,但我们 ...
- Windows下配置scrapy需要MVC的14.0版本(转载)
转载于--http://blog.csdn.net/MrWilliamVs/article/details/77130965 杨煜冬煜杨的博客,他的博客比较杂,Java.Python都有--http: ...
- Codevs1062路由选择
/* #include<iostream> #include<cstdio> #include<cstring> #define MAXN 301 using na ...