解题心得:

  1. 这题涉及概率问题,所以要运用概率的知识进行解答。题目要求不被抓到的概率,但是给出的是被抓到的概率,所要用1减去后得到答案。最好使用double类型,避免精度问题导致WA。
  2. 先算出可以抢劫的总钱数,以此动态规划。

Robberies

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 23012 Accepted Submission(s): 8489

Problem Description

The aspiring Roy the Robber has seen a lot of American movies, and knows that the bad guys usually gets caught in the end, often because they become too greedy. He has decided to work in the lucrative business of bank robbery only for a short while, before retiring to a comfortable job at a university.

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.

Input

The first line of input gives T, the number of cases. 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 .

Output

For each test case, output a line with the maximum 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.

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

2

4

6

Source

IDI Open 2009

#include<stdio.h>
#include<iostream>
#include<math.h>
using namespace std;
const int maxsize = 10010;
struct ai
{
double p;
int v;
}a[maxsize];
int main()
{
long long totle;
double d[maxsize];
int t;
cin>>t;
while(t--)
{
totle = 0; int n;
double pro;
cin>>pro>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i].v>>a[i].p;
totle += a[i].v;
}
d[0] = 1;//这个初始化很重要。
for(int i=1;i<=totle;i++)
d[i] = 0;
for(int i=1;i<=n;i++)
{
for(int j=totle;j>=a[i].v;j--)
{
d[j] = max(d[j],d[j-a[i].v]*(1-a[i].p));
}
}
for(int i=totle;i>=0;i--)
{
if(d[i] >= (1-pro))
{
cout<<i<<endl;
break;
}
}
}
return 0;
}

最新文章

  1. C# 多线程之Task资料
  2. Objective-C 快速入门--基础(五)
  3. 使用enum建立简单的状态机
  4. 写sql语句连接的时候注意的一个小细节
  5. CSS子元素margin-top对于父元素的影响
  6. 使用SecureRandom类替代Random类
  7. [转贴]从零开始学C++之STL(二):实现一个简单容器模板类Vec(模仿VC6.0 中 vector 的实现、vector 的容量capacity 增长问题)
  8. NOI2015
  9. 【filezilla】 ubuntu下安装filezilla
  10. Ugly Problem
  11. Vue.js安装
  12. flex盒模型 详细解析
  13. 拾人牙慧篇之——linux文件挂载,基于nfs的文件共享系统安装配置
  14. Python学习基础笔记(全)
  15. Numpy 笔记: 多维数组的切片(slicing)和索引(indexing)【转】
  16. 【C++】vector内存机制和性能分析
  17. html语义化练习易牛课堂代码
  18. Python_装饰器_29
  19. Java继承与多态浅析
  20. atime,mtime,ctime 的理解

热门文章

  1. Poj 1743——Musical Theme——————【后缀数组,求最长不重叠重复子串长度】
  2. Docker | 第七章:Docker Compose服务编排介绍及使用
  3. 性能测试学习第十天_controller
  4. 符号替换问题:请实现一个函数,将一个字符串中的空格替换成“%20”。例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。
  5. 微信小程序:从本地相册选择图片或使用相机拍照。
  6. 报错:&#39;byte&#39; does not name a type
  7. centos6.2安装内核
  8. Python 加持,给你更有趣的 Azure 虚拟机开关重启方法!
  9. chrome中清除dns缓存
  10. LeetCode Valid Palindrome 有效回文(字符串)