题意:

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. poj 1026 Cipher

    置换群就可以搞定!!! 注意下格式就好了…… #include<iostream> #include<stdio.h> #include<algorithm> #i ...

  2. Spring整合Ibatis

    Spring整合Ibatis javaibatisspring 所需jar清单           ibatis-2.*.jar    *为任意版本,下同,ibatis工作包           sp ...

  3. hdu 1426 Sudoku Killer

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1426 #include<stdio.h> #include<math.h> #in ...

  4. js call apply bind简单的理解

    相同点:JS中call与apply方法可以改变某个函数执行的上下文环境,也就是可以改变函数内this的指向.区别:call与apply方法的参数中,第一个参数都是指定的上下文环境或者指定的对象,而ca ...

  5. 用React.addons.TestUtils、Jasmine进行单元测试

    一.用到的工具 1.React.addons.TestUtils 2.Jasmine 3.Browserify(处理jsx文件的require依赖关系) 4.Reactify(能和browserify ...

  6. tomcat作为windows服务启动失败解决方法

    再使用如下方法注册windows服务时,出现问题: set CATALINA_BASE=E:\tomcat\tomcat-web-server set CATALINA_HOME=E:\tomcat\ ...

  7. 解决 “无法安装 Visual Studio 2010 Service Pack 1,因为此计算机的状态不支持”

    http://blog.csdn.net/davidhsing/article/details/8762621 无法安装Microsoft visual studio 2010 service pac ...

  8. 迷宫问题(bfs的应用)

    问题描述: 定义一个二维数组N*M(其中2<=N<=10;2<=M<=10),如5 × 5数组下所示: int maze[5][5] = { 0, 1, 0, 0, 0, 0, ...

  9. git跨平台换行符不兼容

    https://help.github.com/articles/dealing-with-line-endings/#platform-all

  10. Request.Querystring中文乱码问题解决

    现象:近期项目中用到查询字符串传值,如果传递的是英文一切正常,但是传递中文时,使用request.querystring[]得到的是乱码. 原因:不知道为什么,可能是编码不一致问题 解决方法1:修改w ...