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 ...
随机推荐
- Java基础——I/O续
目录 二进制I/O类 文件导航和I/O 二进制I/O类 FileInputStream类和FileOutputStream类 *FileOutputStream(file: File) *FileOu ...
- 【jQuery】鼠标接触按钮后改变图片
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"% ...
- 【转】Android 如何在Eclipse中查看Android API源码 及 support包源码
原文网址:http://blog.csdn.net/vipzjyno1/article/details/22954775 当我们阅读android API开发文档时候,上面的每个类,以及类的各个方法都 ...
- IE8按F12不显示开发人员工具窗口
转:http://www.cnblogs.com/micromouse/archive/2010/07/11/1775174.html 网上搜来的,记录一下,免得以后忘了 F12将开发人员工具启动后, ...
- JS:实用功能
ylbtech-jQuery:函数-导航 添加样式(addClass).移除样式(removeClass) 轮替函数(toggle()) 选项拼加 全选 网页刷点器 jQuery:3.1,添加样式(a ...
- SQL点滴之编辑数据(转)
数据库中的数据编辑是我们遇到的最频繁的工作,这一个随笔中我来总结一下最常用的数据编辑. select into 经常遇到一种情况是,我们希望创建一个新表,表中的数据来源于原有的一个表:原有一个表,但是 ...
- 【C# C++】C#中调用msvcr100.dll中的_beginthreadex函数
msvcr100.dll是VS2010的C运行时库DLL, _beginthreadex开启子线程的函数就在这个DLL里面实现 unsigned long _beginthreadex( voi ...
- 使用MATLAB生成模糊控制的离线查询表
1.打开模糊控制工具箱,编辑输入输出变量的隶属度函数和模糊控制规则,如下图所示,导出为fuzzy_control.fis文件. 2.打开Simulink模块,建立下图所示的系统框图,两输入,一输出,处 ...
- [Hive - Tutorial] Type System 数据类型
数据类型Type System Hive supports primitive and complex data types, as described below. See Hive Data Ty ...
- KVM背靠Linux好乘凉
虚拟化是走向云的第一步,同理,开源虚拟化是走向开源云的第一步.云计算所提供的产品与方案都是围绕着IT资源的新交付与消费模式.云的形式多样,私有云.公有云与混合云,无论哪种云都具有三个关键特征:虚拟化. ...