http://acm.hdu.edu.cn/showproblem.php?pid=4649

枚举当前状态是0或者是1的概率 其实就枚举1的概率 最后概率乘这个数

位运算用得不熟  老出错

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int a[];
char c[];
double p[],dp[];
int main()
{
int i,j,n,kk=;
while(scanf("%d",&n)!=EOF)
{
kk++;
for(i = ; i <= n ; i++)
scanf("%d",&a[i]);
for(i = ; i <= n ; i++)
cin>>c[i];
for(i = ; i <= n ; i++)
scanf("%lf",&p[i]);
double ans=;
for(i = ; i <= ; i++)
{
memset(dp,,sizeof(dp));
if((a[]&(<<i))!=)
dp[] = ;
for(j = ; j <= n ;j++)
{
dp[j] += p[j]*dp[j-];
if(c[j]=='^')
{
if((a[j]&(<<i))!=)
dp[j]+=(-dp[j-])*(-p[j]);
else
dp[j]+=dp[j-]*(-p[j]);
}
if(c[j]=='&')
{
if((a[j]&(<<i))!=)
dp[j]+=dp[j-]*(-p[j]);
}
if(c[j]=='|')
{
if((a[j]&(<<i))!=)
dp[j]+=(-p[j]);
else
dp[j]+=dp[j-]*(-p[j]);
}
}
ans+=(<<i)*dp[n];
}
printf("Case %d:\n%.6f\n",kk,ans);
}
return ;
}

hdu4649Professor Tian的更多相关文章

  1. Hdu 1052 Tian Ji -- The Horse Racing

    Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  2. HDU 1052 Tian Ji -- The Horse Racing(贪心)(2004 Asia Regional Shanghai)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1052 Problem Description Here is a famous story in Ch ...

  3. LA 3266 (贪心) Tian Ji -- The Horse Racing

    题意: 田忌和齐王各有n匹马,如果马的速度比齐王的快就赢200,慢则输200,相等不赔不赚. 已知两人每匹马的速度(为整数)和齐王所排出的马的顺序,问田忌该如何应对才能使收益最大. 分析: 本以为是一 ...

  4. 【策略】UVa 1344 - Tian Ji -- The Horse Racing(田忌赛马)

    Here is a famous story in Chinese history. That was about 2300 years ago. General Tian Ji was a high ...

  5. Tian Ji -- The Horse Racing

    Tian Ji -- The Horse Racing Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Jav ...

  6. UVA 1344 Tian Ji -- The Horse Racing

    Tian Ji -- The Horse Racing Here is a famous story in Chinese history. That was about 2300 years ago ...

  7. HDU 4649 Professor Tian

    Professor Tian Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) T ...

  8. hdoj 1052 Tian Ji -- The Horse Racing【田忌赛马】 【贪心】

    思路:先按从小到大排序, 然后从最快的開始比(如果i, j 是最慢的一端, flag1, flag2是最快的一端 ),田的最快的大于king的 则比較,如果等于然后推断,有三种情况: 一:大于则比較, ...

  9. Tian Ji -- The Horse Racin

    Tian Ji -- The Horse Racin Problem Description Here is a famous story in Chinese history. "That ...

随机推荐

  1. android 登陆案例_sd卡

    代码: <?xml version="1.0"?> -<LinearLayout android:paddingTop="@dimen/activity ...

  2. (int)、(int&)和(int*)的区别(转)

    (1).首先通过一个例子看(int)和(int&)的区别: float a = 1.0f;cout << (int)a << endl;cout << (i ...

  3. Integer ,==,int 的使用

    面试比较常见的题目:自己也经常忘记,所以就记下来了 上代码: Integer a = ,b=; Integer c = ,d=; System.out.println(a==b); System.ou ...

  4. keepalived+haproxy-部署高可用负载均衡

    环境: 准备两台机子,安装haproxy及keepalive都一样,只是配置不一样而已. 这里只说明一台机子上安装haproxy及keepalive. ======================== ...

  5. Asp.net自带导出方法

    ///datatable数据源 filename绝对路径 如:E:\\***.xls DataTable.WriteXml(fileName)

  6. MembershipProvider的Initialize

    背景 前几天为公司的登陆写密码校验,因为是老系统的东西了,数据已经存在了,所以我要知道密码的校验规则是啥,然后业务经理告诉我了是用Membership去做的加密,让我自己去看.之后我又去问了技术经理, ...

  7. PHP中使用cURL

    1.cURL介绍 cURL 是一个利用URL语法规定来传输文件和数据的工具,支持很多协议,如HTTP.FTP.TELNET等.最爽的是,PHP也支持 cURL 库.本文将介绍 cURL 的一些高级特性 ...

  8. Django同步创建models table失败

    django1.8通过manage.py syncdb 执行同步创建models中创建的表格失败 由于syncdb命令在1.9版本中会被remove, 需要改用makemigrations命令进行代替 ...

  9. about家庭智能设备部分硬件模块功能共享【协同工作】solution

    本人设备列表: Onda tablet {Android} wifi Desktop computer {win7.centos7} 外接蓝牙adapter PS interface 键盘.鼠标{与同 ...

  10. 数据结构与算法C语言实现笔记(1)--表

    声明:此一系列博客为阅读<数据结构与算法分析--C语言描述>(Mark Allen Weiss)笔记,部分内容参考自网络:转载请注明出处. 1.表 表是最简单的数据结构,是形如A1.A2. ...