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 for Mac】在Mac终端导入&导出.sql文件
导入 打开终端输入:(前提是已经配置过MySQL环境变量) mysql -u root -p create database name; use name; source 『将.sql文件直接拖拽至终 ...
- 【MySQL】通过select语句把一列数据拼接成一条字符串
通过 GROUP_CONCAT(如下图)
- HDU 5489 Removed Interval
题意:求一段序列中删掉L个连续元素后的LIS. 解法:我的想法很复杂= =怎么说呢……首先用nlogn的方法求LIS得到的序列dp的第i项的意义为上升子序列所有长度为i的序列结尾元素的最小值,那么先倒 ...
- Jedis的JedisSentinelPool源代码分析
概述 Jedis是Redis官方推荐的Java客户端,更多Redis的客户端可以参考Redis官网客户端列表.Redis-Sentinel作为官方推荐的HA解决方案,Jedis也在客户端角度实现了对S ...
- Storm入门教程 第五章 一致性事务【转】
Storm是一个分布式的流处理系统,利用anchor和ack机制保证所有tuple都被成功处理.如果tuple出错,则可以被重传,但是如何保证出错的tuple只被处理一次呢?Storm提供了一套事务性 ...
- kmeans算法的matlab实践
把图像中所有的像素点进行RGB聚类分析,然后输出看结果 img = imread('qq.png'); %取出R矩阵,并将这个R矩阵拉成一列 imgR = img(:,:,1); imgR = img ...
- 通过gdb跟踪Linux内核装载和启动可执行程序过程
作者:吴乐 山东师范大学 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 实验目的:通过对一个简单的可执 ...
- Result consisted of more than one row 错误的解决
创建MySql的存储过程时,发生“Result consisted of more than one row”的错误. 存储过程的代码如下: )) BEGIN SELECT PetName into ...
- Ubuntu 12.04 安装wine1.7
从源码安装wine 我的系统环境:ubuntu 12.04.4 X64 wine版本:wine-1.7.12.tar.bz2 解压:tar -xvf wine-1.7.12.tar.bz2 进入win ...
- 一、python基础笔记(输入输出、list、touple、dict、set)
1.python 环境搭建 http://www.w3cschool.cc/python/python-install.html 2.python输入输出 print 'The quick brow ...