解题心得:

  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;
}

动态规划:HDU-2955-0-1背包问题:Robberies的更多相关文章

  1. HDU 2955(01背包问题)

    M - 01背包 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Descript ...

  2. HDU 2955(0-1背包问题)

    题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87125#problem/M 题目: Description The aspir ...

  3. HDU 2955 Robberies 背包概率DP

    A - Robberies Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submi ...

  4. 详解动态规划(Dynamic Programming)& 背包问题

    详解动态规划(Dynamic Programming)& 背包问题 引入 有序号为1~n这n项工作,每项工作在Si时间开始,在Ti时间结束.对于每项工作都可以选择参加与否.如果选择了参与,那么 ...

  5. 经典递归问题:0,1背包问题 kmp 用遗传算法来解背包问题,hash表,位图法搜索,最长公共子序列

    0,1背包问题:我写笔记风格就是想到哪里写哪里,有很多是旧的也没删除,代码内部可能有很多重复的东西,但是保证能运行出最后效果 '''学点高大上的遗传算法''' '''首先是Np问题的定义: npc:多 ...

  6. HDU 4370 0 or 1 (最短路+最小环)

    0 or 1 题目链接: Rhttp://acm.hust.edu.cn/vjudge/contest/122685#problem/R Description Given a n*n matrix ...

  7. 蓝桥杯 0/1背包问题 (java)

      今天第一次接触了0/1背包问题,总结一下,方便以后修改.不对的地方还请大家不啬赐教! 上一个蓝桥杯的例题: 数据规模和约定 代码: import java.util.Scanner; public ...

  8. HDU - 4370 0 or 1

    0 or 1 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Subm ...

  9. Java实现动态规划法求解0/1背包问题

    摘要: 使用动态规划法求解0/1背包问题. 难度: 初级 0/1背包问题的动态规划法求解,前人之述备矣,这里所做的工作,不过是自己根据理解实现了一遍,主要目的还是锻炼思维和编程能力,同时,也是为了增进 ...

  10. Hdu 2955 Robberies 0/1背包

    Robberies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

随机推荐

  1. Hibernate的事务管理

    Hibernate的事务管理 事务(Transaction)是工作中的基本逻辑单位,可以用于确保数据库能够被正确修改,避免数据只修改了一部分而导致数据不完整,或者在修改时受到用户干扰.作为一名软件设计 ...

  2. SpringBoot | 第二十五章:日志管理之自定义Appender

    前言 前面两章节我们介绍了一些日志框架的常见配置及使用实践.一般上,在开发过程中,像log4j2.logback日志框架都提供了很多Appender,基本上可以满足大部分的业务需求了.但在一些特殊需求 ...

  3. orcale函数

    字符函数    1.ASCII 返回与指定的字符对应的十进制数;  select ascii('A') A,ascii('a') a,ascii('0') zero,ascii(' ') space ...

  4. Android入门:封装一个HTTP请求的辅助类

    前面的文章中,我们曾经实现了一个HTTP的GET 和 POST 请求: 此处我封装了一个HTTP的get和post的辅助类,能够更好的使用: 类名:HttpRequestUtil 提供了如下功能: ( ...

  5. nsight 中出现method could not be resolved 报错

    解决的方法就是现在编译选项中取消该报错. 项目右键->属性->c/c++常规->Code Analysis,选择"Use project settings"  中 ...

  6. [荐]推荐一个shell学习的网站

    最近再用shell脚本,发现一个脚本学习的网站,非常好用,特此推荐一下. shell学习网站链接:http://c.biancheng.net/cpp/shell/

  7. SqlServer Alwayson 搭建排错记录(二)

    下面记录下建立好alwayson可用性组后,向可用性组内添加数据库出现过的问题及解决方法 一.数据库未处于恢复状态 将数据库联接到可用性组的时候报错: 数据库“XXXX”未处于恢复状态,而此状态是镜像 ...

  8. .net密码找回

    using System; using System.Collections.Generic; using System.Text; using System.Net.Mail; using Syst ...

  9. JavaScript_HTML DEMO_3_节点

    创建新的HTML元素 删除已有的HTML元素 <body> <div id="div1"> <p id="p1">这是一个段 ...

  10. 汇编:jmp系列跳转指令总结

    助记方法: J:跳转C: 进位位置位N: 否S: 符号位置位o: 溢出位置位Z: 零标志位置位E: 等于P:奇偶位置位A: AboveB: BelowL: Less (Little的比较级)G: Gr ...