题意:

n个人,开始有一个容量为k得背包,击败一个人背包可以获得一定容量或得到一个财富(放入背包内),给出击败每个人的概率,求至少击败l个人,且背包容量大于获得的总财富值的概率

分析:

状态好确定,dp[i][j][k]表示前i个人击败j个背包容量是k是的概率,求概率正推,要注意这时背包容量能为负,我们把容量都加上B。

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define read freopen("in.txt", "r", stdin)
#define B 201
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = ;
double dp[][][*B+];
int a[],p[];
int n,l,k;
void solve(){
memset(dp,,sizeof(dp));
dp[][][B+k]=;
for(int i=;i<=n;++i)
for(int j=;j<=i;++j)
for(int k=;k<=*B;++k)
{
dp[i][j][k]+=dp[i-][j][k]*(-p[i]/100.0);//未击败第i个人
if(a[i]==-){
if(k>)//必须能放下一个财富
dp[i][j+][k-]+=dp[i-][j][k]*(p[i]/100.0);
}
else{
if(k+a[i]>*B)
dp[i][j+][*B]+=dp[i-][j][k]*(p[i]/100.0);
else
dp[i][j+][k+a[i]]+=dp[i-][j][k]*(p[i]/100.0);
}
}
    //符合条件的情况的概率和
double total=0.0;
for(int j=l;j<=n;++j)
for(int k=B;k<=*B;++k)
total+=dp[n][j][k];
printf("%.12lf\n",total);
}
int main()
{
while(~scanf("%d%d%d",&n,&l,&k)){
for(int i=;i<=n;++i)
scanf("%d",&p[i]);
for(int i=;i<=n;++i)
scanf("%d",&a[i]); solve();
}
return ;
}

Codeforces 167B Wizards and Huge Prize(概率dp)的更多相关文章

  1. Codeforces Round #114 (Div. 1) B. Wizards and Huge Prize 概率dp

    B. Wizards and Huge Prize Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...

  2. CodeForces 167B - Wizards and Huge Prize 期望概率dp

    初步分析:把赢了的巡回赛的a值加起来就是最后的剩余空间 这个明显的是状态转移的dp啊,然而他的状态比较骚是个数组,表示剩余空间,f(i,j,b),i表示比到第几场,j表示赢了几场,b就是里面的核心状态 ...

  3. [Codeforces-div.1 167B] Wizards and Huge Prize

    [Codeforces-div.1 167B] Wizards and Huge Prize 试题分析 注意到每个物品互相独立,互不干扰之后就非常好做了. 算出一个物品最后的价值期望,然后乘以K即可. ...

  4. [codeforces167B]Wizards and Huge Prize

    B. Wizards and Huge Prize time limit per test: 2 seconds memory limit per test: 256 megabytes input: ...

  5. Codeforces 678E. Another Sith Tournament(概率DP,状压)

    Codeforces 678E. Another Sith Tournament 题意: n(n<=18)个人打擂台赛,给定任意两人对决的胜负概率,比赛规则:可指定一人作为最开始的擂主,每次可指 ...

  6. Codeforces B. Bad Luck Island(概率dp)

    题目描述: Bad Luck Island time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  7. Codeforces 148D Bag of mice:概率dp 记忆化搜索

    题目链接:http://codeforces.com/problemset/problem/148/D 题意: 一个袋子中有w只白老鼠,b只黑老鼠. 公主和龙轮流从袋子里随机抓一只老鼠出来,不放回,公 ...

  8. Codeforces 601C Kleofáš and the n-thlon 概率dp

    Kleofáš and the n-thlon 我们可以用dp算出比当前这个人得分少的概率, 然后人数乘概率就好啦. dp[ i ][ j ]表示进行了 i 轮 得分为 j 的概率, 因为每个人都是独 ...

  9. Codeforces 280C Game on tree【概率DP】

    Codeforces 280C Game on tree LINK 题目大意:给你一棵树,1号节点是根,每次等概率选择没有被染黑的一个节点染黑其所有子树中的节点,问染黑所有节点的期望次数 #inclu ...

随机推荐

  1. [SQL Server系] -- 约束

    什么是约束? 约束(Constraint)是SQL Server中提供的 自动保存数据库完整性 的一种方法,定义了可输入表或表的列中的数据限制条件. SQL Server中共有5中约束 PRIMARY ...

  2. Exceptionin thread "main" java.lang.UnsatisfiedLinkError:org.apache.hadoop.util.NativeCrc32.nativeComputeChunkedSumsByteArray(II[BI[BIILjav

    在eclipse上运行hadoop报错:Exceptionin thread "main" java.lang.UnsatisfiedLinkError:org.apache.ha ...

  3. AutoEventWireup解释

    这一事件聚合了当前页是否自动关联某些特殊事件. 首先,从浏览器页面出发的事件不能立刻在本地得到处理,而是POST至服务器上,因此,asp.net建立了委托(代理)机制.在建立一个事件的同事,建立相应的 ...

  4. Linux 2.4.x内核软中断机制

    http://www.ibm.com/developerworks/cn/linux/kernel/interrupt/ 软中断概况 软中断是利用硬件中断的概念,用软件方式进行模拟,实现宏观上的异步执 ...

  5. ios UIView常用动画效果

    一 //调用 1 2 3 4 5 6 if(m_viewScenario.superview == nil)<br>{     m_viewScenario.alpha = 1.0;    ...

  6. Hibernate逍遥游记-第13章 映射实体关联关系-001用外键映射一对一(<many-to-one unique="true">、<one-to-one>)

    1. <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hi ...

  7. 10、JPA_映射双向多对多的关联关系

    双向多对多的关联关系 双向多对多的关联关系(抽象成A-B)具体体现:A中有B的集合的引用,同时B中也有对A的集合的引用.A.B两个实体对应的数据表靠一张中间表来建立连接关系. 同时我们还知道,双向多对 ...

  8. Java API —— Math类

    1.Math类概述         Math 类包含用于执行基本数学运算的方法,如初等指数.对数.平方根和三角函数.  2.成员变量         public static final doubl ...

  9. Tomcat 自动上传的删除文件

    解决方案: 在 sever.xml 中的 Context 中建一个虚拟路径,指定到服务器硬盘中的其他位置,比如放在 d: 的某个目录下. 同时可以将这个路径映射成为你当前工程名后面带个目录,比如说 / ...

  10. socklen_t在windows和linux平台下的头文件定义

    windows平台下:头文件:#include<ws2tcpip.h> linux平台下:下面两个头文件都有定义:1)#include <sys/socket.h>2)#inc ...