hdu2955(概率DP)

For a few months now,
Roy has been assessing the security of various banks and the amount of cash they
hold. He wants to make a calculated risk, and grab as much money as
possible.
His mother, Ola, has decided upon a tolerable probability
of getting caught. She feels that he is safe enough if the banks he robs
together give a probability less than this.
For each scenario, the first line of input gives a floating point number P, the
probability Roy needs to be below, and an integer N, the number of banks he has
plans for. Then follow N lines, where line j gives an integer Mj and a floating
point number Pj .
Bank j contains Mj millions, and the probability of
getting caught from robbing it is Pj .
number of millions he can expect to get while the probability of getting caught
is less than the limit set.
Notes and Constraints
0 < T <=
100
0.0 <= P <= 1.0
0 < N <= 100
0 < Mj <= 100
0.0
<= Pj <= 1.0
A bank goes bankrupt if it is robbed, and you may assume
that all probabilities are independent as the police have very low funds.
0.04 3
1 0.02
2 0.03
3 0.05
0.06 3
2 0.03
2 0.03
3 0.05
0.10 3
1 0.03
2 0.02
3 0.05
4
6
#include<bits/stdc++.h>
using namespace std;
double dp[10005]; //x下标表示能抢够这个金钱的概率
int main()
{
int T,N,m[105],n,i,j,k,max_money;
double P,p[105];
cin>>T;
while(T--){memset(dp,0,sizeof(dp));
dp[0]=1,max_money=0;
cin>>P>>N;
for(i=1;i<=N;++i) {
cin>>m[i]>>p[i];
p[i]=1.0-p[i];
max_money+=m[i];
}
for(i=1;i<=N;++i)
for(j=max_money;j>=m[i];--j)
dp[j]=max(dp[j],dp[j-m[i]]*p[i]);
for(i=max_money;i>=0;--i) if(dp[i]>1-P||i==0) {cout<<i<<endl;break;}
}
return 0;
}
hdu2955(概率DP)的更多相关文章
- Codeforces 28C [概率DP]
/* 大连热身D题 题意: 有n个人,m个浴室每个浴室有ai个喷头,每个人等概率得选择一个浴室. 每个浴室的人都在喷头前边排队,而且每个浴室内保证大家都尽可能均匀得在喷头后边排队. 求所有浴室中最长队 ...
- HDU 4405 Aeroplane chess (概率DP)
题意:你从0开始,要跳到 n 这个位置,如果当前位置是一个飞行点,那么可以跳过去,要不然就只能掷骰子,问你要掷的次数数学期望,到达或者超过n. 析:概率DP,dp[i] 表示从 i 这个位置到达 n ...
- POJ 2096 Collecting Bugs (概率DP)
题意:给定 n 类bug,和 s 个子系统,每天可以找出一个bug,求找出 n 类型的bug,并且 s 个都至少有一个的期望是多少. 析:应该是一个很简单的概率DP,dp[i][j] 表示已经从 j ...
- POJ 2151 Check the difficulty of problems (概率DP)
题意:ACM比赛中,共M道题,T个队,pij表示第i队解出第j题的概率 ,求每队至少解出一题且冠军队至少解出N道题的概率. 析:概率DP,dp[i][j][k] 表示第 i 个队伍,前 j 个题,解出 ...
- 概率DP light oj 1030
t组数据 n块黄金 到这里就捡起来 出发点1 到n结束 点+位置>n 重掷一次 dp[i] 代表到这里的概率 dp[i]=(dp[i-1]+dp[i-2]... )/6 如果满6个的话 否则 ...
- hdu 4050 2011北京赛区网络赛K 概率dp ***
题目:给出1-n连续的方格,从0开始,每一个格子有4个状态,左右脚交替,向右跳,而且每一步的步长必须在给定的区间之内.当跳出n个格子或者没有格子可以跳的时候就结束了,求出游戏的期望步数 0:表示不能到 ...
- [转]概率DP总结 by kuangbin
概率类题目一直比较弱,准备把kuangbin大师傅总结的这篇题刷一下! 我把下面的代码换成了自己的代码! 原文地址:http://www.cnblogs.com/kuangbin/archive/20 ...
- SGU 422 Fast Typing(概率DP)
题目大意 某人在打字机上打一个字符串,给出了他打每个字符出错的概率 q[i]. 打一个字符需要单位1的时间,删除一个字符也需要单位1的时间.在任意时刻,他可以花 t 的时间检查整个打出来的字符串,并且 ...
- HDU 4050 wolf5x(动态规划-概率DP)
wolf5x Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- 概率dp入门
概率DP主要用于求解期望.概率等题目. 转移方程有时候比较灵活. 一般求概率是正推,求期望是逆推.通过题目可以体会到这点. poj2096:Collecting Bugs #include <i ...
随机推荐
- ELK学习笔记之Logstash详解
0x00 Logstash概述 官方介绍:Logstash is an open source data collection engine with real-time pipelining cap ...
- LOJ10066 新的开始
LOJ10066 新的开始 prim 典型题.碰到这种情况,只要建一个虚拟节点,和其他的点连边,按题目给权值即可 代码中把n+1当成虚拟节点 懒得写kruskal就用prim了 #include< ...
- tomcat热启动没问题, 访问项目报500解决办法
新建maven项目 添加热启动 启动访问项目报错 报错提示 解决办法 思路:包冲突 在pom.xml中添加servlet <dependency> <groupId>javax ...
- 20145332卢鑫 WEB基础
20145332卢鑫 WEB基础 实验过程 1.环境配置 2.简单的网页编写 3.javascript相关 1.相关概念:JavaScript是一种广泛用于客户端Web开发的脚本语言,常用来给HTML ...
- linux下安装微信小程序开发工具
一.环境:: ubuntu 16.04 二.安装过程: 2.1 安装wine sudo apt-get install wine 2.2 安装nwjs-sdk 2.2.1 下载linux版nwjs-s ...
- luogu3935 Calculating
标题也许叫整除分块吧 求\(1\)到\(n\)因数的个数\(\sum_{i=1}^n(\sum_{d|n}1)\) 范围\(1e14\)时限3s \(n\sqrt{n}\)的暴力铁定gg 分开考虑 \ ...
- sql 锁
数据库中不使用锁时可能出现的问题: 1.更新丢失(Lost update) 两个事务都同时更新一行数据,但是第二个事务却中途失败退出,导致对数据的两个修改都失效了.这是因为系统没有执行任何的锁操作,因 ...
- SPOJ LAS(BFS)题解
题目:VJ 思路: BFS+回溯,但是要剪枝,看了dalao的题解,超时+WA无数发,终于过了 #include<cstdio> #include<cstring> #incl ...
- C#学习笔记(二):变量、数据类型和运算符
变量.数据类型 给变量赋值,如果想指定float,在数字后面加上F/f:如果想指定decimal,在数字后面加上m. 0-9:48-57 A-Z:65-90 a-z:97-122 ...
- POJ 3624 Charm Bracelet(0-1背包模板)
http://poj.org/problem?id=3624 题意:给出物品的重量和价值,在重量一定的情况下价值尽可能的大. 思路:经典0-1背包.直接套用模板. #include<iostre ...