集训第六周 数学概念与方法 概率 N题
Description
As Harry Potter series is over, Harry has no job. Since he wants to make quick money, (he wants everything quick!) so he decided to rob banks. He wants to make a calculated risk, and grab as much money as possible. But his friends - Hermione and Ron have decided upon a tolerable probabilityP of getting caught. They feel that he is safe enough if the banks he robs together give a probability less than P.
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case contains a real number P, the probability Harry needs to be below, and an integer N (0 < N ≤ 100), the number of banks he has plans for. Then follow N lines, where line j gives an integer Mj (0 < Mj ≤ 100) and a real number Pj . Bank j contains Mj millions, and the probability of getting caught from robbing it is Pj. A bank goes bankrupt if it is robbed, and you may assume that all probabilities are independent as the police have very low funds.
Output
For each case, print the case number and the maximum number of millions he can expect to get while the probability of getting caught is less than P.
Sample Input
3
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
Sample Output
Case 1: 2
Case 2: 4
Case 3: 6
题意:哈利波特毕业了,由于没找到工作,他想去抢银行,他的两个基友为他算了一卦,告诉他如果他被抓的概率小于或等于P,他就会很安全,否则就一定会被抓。
于是哈利波特去调查了一下,记录每个银行的存钱量和被抓的风险,要求你计算他最多能抢多少钱
先转化一下:改限制为不被抓的概率大于等于(1-P),再将这个问题转化为背包01问题
dp(i)代表抢i枚大钱不被抓的概率
dp (i)=max { dp ( i - a[j] ) *( 1- p[j] ) , dp[i] } (i--0~所有银行的钱,j遍历所有银行)
#include"iostream"
#include"cstdio"
#include"cstring"
using namespace std;
const int maxn=;
double dp[maxn*maxn],P,b[maxn];
int n,a[maxn],sum,ca=;
void Init()
{
cin>>P>>n;
sum=;
for(int i=;i<n;i++)
{
cin>>a[i]>>b[i];
sum+=a[i];
}
memset(dp,,sizeof(dp));
} void Work()
{
dp[]=;
for(int i=;i<n;i++)
{
for(int j=sum;j>=a[i];j--)
{
dp[j]=max(dp[j-a[i]]*(-b[i]),dp[j]);
}
}
} void Print()
{
cout<<"Case "<<ca++<<": ";
for(int i=sum;i>=;i--)
{
if(dp[i]>(-P))
{
cout<<i<<endl;
break;
}
}
} int main()
{
int T;
cin>>T;
while(T--)
{
Init();
Work();
Print();
}
return ;
}
集训第六周 数学概念与方法 概率 N题的更多相关文章
- 集训第六周 数学概念与方法 概率 F题
Submit Status Description Sometimes some mathematical results are hard to believe. One of the common ...
- 集训第六周 数学概念与方法 概率 数论 最大公约数 G题
Description There is a hill with n holes around. The holes are signed from 0 to n-1. A rabbit must h ...
- 集训第六周 数学概念与方法 数论 筛素数 H题
Description 小明对数的研究比较热爱,一谈到数,脑子里就涌现出好多数的问题,今天,小明想考考你对素数的认识. 问题是这样的:一个十进制数,如果是素数,而且它的各位数字和也是素数,则称之为“ ...
- 集训第六周 数学概念与方法 计数 排列 L题
Description 大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了! 做好“一件”事情尚且不易,若想永远成功而总从不失败,那更是难上加难了,就像花钱总是比挣钱容易的道理一样. 话 ...
- 集训第六周 数学概念与方法 J题 数论,质因数分解
Description Tomorrow is contest day, Are you all ready? We have been training for 45 days, and all g ...
- 集训第六周 数学概念与方法 数论 线性方程 I题
Description The Sky is Sprite. The Birds is Fly in the Sky. The Wind is Wonderful. Blew Throw the Tr ...
- 集训第六周 数学概念与方法 UVA 11181 条件概率
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18546 题意:有n个人会去超市,其中只有r个人会买东西,每个人独自买东西的概 ...
- 集训第六周 数学概念与方法 UVA 11722 几何概型
---恢复内容开始--- http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=31471 题意,两辆火车,分别会在[t1,t2],[ ...
- 集训第六周 古典概型 期望 D题 Discovering Gold 期望
Description You are in a cave, a long cave! The cave can be represented by a 1 x N grid. Each cell o ...
随机推荐
- [CQOI 2006]线段树之简单题
Description 有一个n个元素的数组,每个元素初始均为0.有m条指令,要么让其中一段连续序列数字反转--0变1,1变0(操作1),要么询问某个元素的值(操作2).例如当n=20时,10条指令如 ...
- 拓扑排序/DFS HDOJ 4324 Triangle LOVE
题目传送门 题意:判三角恋(三元环).如果A喜欢B,那么B一定不喜欢A,任意两人一定有关系连接 分析:正解应该是拓扑排序判环,如果有环,一定是三元环,证明. DFS:从任意一点开始搜索,搜索过的点标记 ...
- 贪心 Codeforces Round #109 (Div. 2) B. Combination
题目传送门 /* 贪心:按照能选的个数和点数降序排序,当条件不符合就break,水题啊! */ #include <cstdio> #include <algorithm> # ...
- 输入一个秒数,要求转换为XX小时XX分XX秒的格式输出出来;
package arithmetic; import java.util.Scanner; import org.junit.Test; public class Test02 { /** * 输入一 ...
- AsyncTask官方教程-推荐用AsyncTask少用Thread
Using AsyncTask AsyncTask allows you to perform asynchronous work on your user interface. It perform ...
- iOS判断输入的字符串是否是纯数字
主要用于判断输入到TextField的内容是不是数字,比如需要输入电话号码的时候. 网上查看了一些资料,一般都是通过协议. 以下内容来自:http://www.2cto.com/kf/201404/2 ...
- [转]Business Model Canvas(商业模式画布):创业公司做头脑风暴和可行性测试的一大利器
本文转自:http://www.36kr.com/p/214438.html 本文来自First Round Review,他们准备的文章既讲故事,还同时向创业者提供可操作的建议,以助力打造优秀的公司 ...
- visual assist x 注释配置
/******************************************************************** created: $DATE$ created: $DAY$ ...
- joomla建站-双语CMS系统开发的实现
首先,请确保你的网站安装了你所需的双语语言,详细安装过程见:https://www.cnblogs.com/surfer/p/9619345.html 第一步:设置内容管理 可以按照个人需求进行语言编 ...
- RFTWEB测试对象抓取的方法
本文转自:http://feiyeguohai.iteye.com/blog/1468576 Rational Functional Tester (RFT) 作为 IBM 自己设计研发的自动化测试工 ...