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/167/problem/B
Description
One must train much to do well on wizardry contests. So, there are numerous wizardry schools and magic fees.
One of such magic schools consists of n tours. A winner of each tour gets a huge prize. The school is organised quite far away, so one will have to take all the prizes home in one go. And the bags that you've brought with you have space for no more than k huge prizes.
Besides the fact that you want to take all the prizes home, you also want to perform well. You will consider your performance good if you win at least l tours.
In fact, years of organizing contests proved to the organizers that transporting huge prizes is an issue for the participants. Alas, no one has ever invented a spell that would shrink the prizes... So, here's the solution: for some tours the winner gets a bag instead of a huge prize. Each bag is characterized by number ai — the number of huge prizes that will fit into it.
You already know the subject of all tours, so you can estimate the probability pi of winning the i-th tour. You cannot skip the tour under any circumstances.
Find the probability that you will perform well on the contest and will be able to take all won prizes home (that is, that you will be able to fit all the huge prizes that you won into the bags that you either won or brought from home).
Input
The first line contains three integers n, l, k (1 ≤ n ≤ 200, 0 ≤ l, k ≤ 200) — the number of tours, the minimum number of tours to win, and the number of prizes that you can fit in the bags brought from home, correspondingly.
The second line contains n space-separated integers, pi (0 ≤ pi ≤ 100) — the probability to win the i-th tour, in percents.
The third line contains n space-separated integers, ai (1 ≤ ai ≤ 200) — the capacity of the bag that will be awarded to you for winning the i-th tour, or else -1, if the prize for the i-th tour is a huge prize and not a bag.
Output
Print a single real number — the answer to the problem. The answer will be accepted if the absolute or relative error does not exceed10 - 6.
Sample Input
3 1 0
10 20 30
-1 -1 2
Sample Output
0.300000000000
HINT
题意
有n个人,你需要至少打败l个人,你一开始的背包容量是k
打败每个人的概率是p[i],如果a[i]=-1,那么说明这个人打败之后,会给你奖品,否则就会给你一个容量为a[i]的背包
每个奖品带回家,都需要容量为1的背包
问你至少打败l个人,并且把胜利品全部都能带回去的概率是多少
题解:
dp[i][j][k]表示我目前挑战到第i个人,打败了j个人,我把所有胜利品都背回去之后的背包剩余容量为k
然后转移转移就好了~
代码:
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std; int tmp = ;
double dp[][][];
double p[];
int a[];
int main()
{
int n,l,k;
scanf("%d%d%d",&n,&l,&k);
for(int i=;i<=n;i++)
{
scanf("%lf",&p[i]);
p[i]/=100.0;
}
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
dp[][][tmp+k]=;
for(int i=;i<n;i++)
{
for(int j=;j<=i;j++)
{
for(int t=;t<=;t++)
{
if(a[i+]==-)
{
if(t>)dp[i+][j+][t-] += dp[i][j][t] * p[i+];
dp[i+][j][t] += dp[i][j][t]*(-p[i+]);
}
else
{
int pl = min(t + a[i+],);
dp[i+][j+][pl] += dp[i][j][t]*p[i+];
dp[i+][j][t] += dp[i][j][t]*(-p[i+]);
}
}
}
}
double ans = ;
for(int i=l;i<=n;i++)
for(int j=tmp;j<=;j++)
ans += dp[n][i][j];
printf("%.10f\n",ans);
}
Codeforces Round #114 (Div. 1) B. Wizards and Huge Prize 概率dp的更多相关文章
- Codeforces Round #114 (Div. 1) A. Wizards and Trolleybuses 物理题
A. Wizards and Trolleybuses Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...
- Codeforces Round #114 (Div. 1) D. Wizards and Roads 笛卡尔树+树贪心+阅读题
D. Wizards and Roads 题目连接: http://www.codeforces.com/contest/167/problem/D Description In some count ...
- Codeforces Round #114 (Div. 1) E. Wizards and Bets 高斯消元
E. Wizards and Bets 题目连接: http://www.codeforces.com/contest/167/problem/E Description In some countr ...
- Codeforces Round #114 (Div. 1) C. Wizards and Numbers 博弈论
C. Wizards and Numbers 题目连接: http://codeforces.com/problemset/problem/167/C Description In some coun ...
- Codeforces Round #284 (Div. 1) B. Name That Tune(概率DP)(难)
B. Name That Tune time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces 167B Wizards and Huge Prize(概率dp)
题意: n个人,开始有一个容量为k得背包,击败一个人背包可以获得一定容量或得到一个财富(放入背包内),给出击败每个人的概率,求至少击败l个人,且背包容量大于获得的总财富值的概率 分析: 状态好确定,d ...
- Codeforces Round #114 (Div. 2)
Codeforces Round #114 (Div. 2) 代码 Codeforces Round #114 (Div. 2) C. Wizards and Trolleybuses 思路 每条车的 ...
- Codeforces Round #396 (Div. 2) A B C D 水 trick dp 并查集
A. Mahmoud and Longest Uncommon Subsequence time limit per test 2 seconds memory limit per test 256 ...
- Codeforces Round #327 (Div. 2) A. Wizards' Duel 水题
A. Wizards' Duel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/prob ...
随机推荐
- MySQL基础之第11章 插入、更新与删除数据
11.1.插入数据 11.1.1.为表的所有字段插入数据 1.INSERT语句中不指定具体的字段名 insert into 表名 values (值1,值2…值n)2.INSERT语句 ...
- 总结c++ primer中的notes
转载:http://blog.csdn.net/ace_fei/article/details/7386517 说明: C++ Primer, Fourth Edition (中英文)下载地址:htt ...
- cadence异型孔
1:画route path的边框,画在board geometry的ncroute_path层上,可以用zcopy (暂时没用过) 没有的话可能:WARNING: No route path ...
- 在ASP.NET下做了一个实验MVC的小东西
星期五下班前一时兴起,对MVC发表了一点看法.后来就想干脆弄个小东西来验证一些自己的想法帮组理清思路.所要源代码的免了,3个小时的急就章实在是乱得可以,既没有好的架构,也没有任何代码质量可言,主要是实 ...
- Chapter4:表达式
左值和右值 当一个对象被用作右值的时候,用的是对象的值(内容),当对象被用作左值的时候,用的是对象的身份(在内存中的位置). 一个重要的原则是需要右值的地方可以用左值来代替,但是不能把右值当作左值使用 ...
- wuzhicms水印的设置
- Codeforces Round #365 (Div. 2) C - Chris and Road 二分找切点
// Codeforces Round #365 (Div. 2) // C - Chris and Road 二分找切点 // 题意:给你一个凸边行,凸边行有个初始的速度往左走,人有最大速度,可以停 ...
- oc_转_构造对象的方法,以及类的继承
一.构造方法 (一)构造方法的调用 完整的创建一个可用的对象:Person *p=[Person new]; New方法的内部会分别调用两个方法来完成2件事情: 1) 使用alloc方法来分配存储空间 ...
- web.py处理文件上传
#coding=utf8 import web urls = ('/','Home', '/upload', 'Upload') app = web.application(urls, globals ...
- -bash: ./radar.sh: /bin/sh^M: bad interpreter: 没有那个文件或目录
运行shell脚本时,报下面这个错误: -bash: ./radar.sh: /bin/sh^M: bad interpreter: 没有那个文件或目录 错误分析: 因为操作系统是windows, ...