题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

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

Problem solving report:

Description: 给一个最大风险值,有很多银行,Mj表示第j个银行有多少钱,Pj表示抢这个银行的风险值,求在给定最大风险值的范围内最多能抢到的金额。
Problem solving: 01背包问题,但需要将能抢来的最多的钱最为背包容量,转换成求抢劫一定金额时最大的逃跑的概率!此题目的核心和关键就是进行转化。

#include <bits/stdc++.h>
using namespace std;
int v[105], n, ans;
double w[105], dp[10005], p;
int main() {int t;scanf("%d", &t);while (t--) {ans = 0;memset(dp, 0, sizeof(dp));scanf("%lf%d", &p, &n);for (int i = 0; i < n; i++) {scanf("%d%lf", &v[i], &w[i]);w[i] = 1 - w[i];ans += v[i];}p = 1 - p;dp[0] = 1;for (int i = 0; i < n; i++) {for (int j = ans; j >= v[i]; j--)dp[j] = max(dp[j], dp[j - v[i]] * w[i]);}for (int i = ans; i >= 0; i--) {if (dp[i] >= p) {printf("%d\n", i);break;}}}return 0;
}

HDU - Robberies(01背包)相关推荐

  1. hdu 2955 01背包

    http://acm.hdu.edu.cn/showproblem.php?pid=2955 如果认为:1-P是背包的容量,n是物品的个数,sum是所有物品的总价值,条件就是装入背包的物品的体积和不能 ...

  2. hdu 3732(01背包转多重背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3732 思路:这么大的数据,用01背包肯定会TLE的,01背包转多重背包..最多也就11*11=121件 ...

  3. HDU 3466 01背包变形

    给出物品数量N和总钱数M 对于N个物品.每一个物品有其花费p[i], 特殊值q[i],价值v[i] q[i] 表示当手中剩余的钱数大于q[i]时,才干够买这个物品 首先对N个物品进行 q-p的排序,表 ...

  4. hdu 1574(01背包)

    RP问题 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Des ...

  5. HDU 2546(01背包)

    饭卡 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...

  6. hdu 2184 01背包变形

    转自:http://blog.csdn.net/liuqiyao_01/article/details/8753686 题意:这是又是一道01背包的变体,题目要求选出一些牛,使smartness和fu ...

  7. HDOJ 2955 Robberies (01背包)

    10397780 2014-03-26 00:13:51 Accepted 2955 46MS 480K 676 B C++ 泽泽 http://acm.hdu.edu.cn/showproblem. ...

  8. HDOJ2955 Robberies(01背包,概率)

    http://acm.hdu.edu.cn/showproblem.php?pid=2955 这道DP题WA了. 今天看了一下,WA在了double max(int x,int y)上,x和y都应该是 ...

  9. hdu 2602 01背包入门

    Many years ago , in Teddy's hometown there was a man who was called "Bone Collector". This ...

最新文章

  1. 工控系统的指纹识别技术
  2. python中怎么做分组问题_详解Python中的分组函数groupby和itertools)
  3. 3.5 梯度校验-机器学习笔记-斯坦福吴恩达教授
  4. NYOJ 518 取球游戏
  5. mysql主从同步简单原理_MYSQL简单主从复制原理及实现
  6. mysql 8重置root密码_如何在MySQL 8中重置root密码
  7. .NET Core实战项目之CMS 第四章 入门篇-Git的快速入门及实战演练
  8. Java反射机制API
  9. 重磅:专门《Vue2.0基础》设计的1套练习题
  10. linux搭建交叉编译器,手把手教你一步一步搭建mips-linux-gcc-4.4.0交叉编译工具
  11. 单例模式之双重检查锁(double check locking)的发展历程
  12. Android开发学习之路-LruCache使用和源码分析
  13. python归并排序算法实现_排序算法之归并排序(附 Python 与 JS 实现)
  14. android 线程使用监控思路分享
  15. Linux服务篇--企业级调度器LVS
  16. Matlab版本svm工具箱,matlab libsvm工具箱
  17. Flutter动画Animation开发指南
  18. mysql身份证来算年龄_MySQL 根据身份证出生年月计算年龄户籍地性别
  19. 一个普通前端的2022年终总结:多病的一年
  20. 通过Vue+flvjs在HTML5中播放flv格式视频文件—demo及api

热门文章

  1. mac安装使用xampp
  2. oracle 数据库精简,Oracle角色精简总结
  3. 续谈大数据之足球盘口赔率水位分析思路及其实现利器
  4. 如何用织梦在本地搭建网站?
  5. 网吧游戏下载期,内置超10000G游戏!
  6. P1071 [NOIP2009 提高组] 潜伏者
  7. 北邮自考计算机专业好过吗,有参加过北京邮电大学自考答辩的吗,难吗
  8. Hash 和 History模式的区别
  9. 洛谷 P2862 [USACO06JAN]把牛Corral the Cows 解题报告
  10. 国内外一些软件开发公司