解题心得:

  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. Java修饰符/关键字

    修饰符分类: 权限修饰符:public.protected.default.private 其他修饰符:abstract.static.final.transient.volatile.native. ...

  2. int,long,long long的数据范围

    unsigned   int   0-4294967295   int   2147483648-2147483647 unsigned long 0-4294967295long   2147483 ...

  3. 使用PM2守护Node.js应用

    PM2简介 PM2是node进程管理工具,可以利用它来简化很多node应用管理的繁琐任务,如性能监控.自动重启.负载均衡等,而且使用非常简单.   安装PM2 $ npm install pm2 -g ...

  4. vscode 插件todo-highlight

    简介 Highlight TODO,FIXME or any annotations within your code. 资源 https://marketplace.visualstudio.com ...

  5. String与Date转换

    public class TimeTraining { public static void changeStr(String str){ str = "137878"; } pu ...

  6. Android应用瘦身

    转:https://zhuanlan.zhihu.com/p/25465537 瘦身的目的 从目的导向来看,我们是不会无缘无故去做一件事情的,那我们对应用瘦身的目的是为了什么?答案是:提高下载转化率. ...

  7. 命令行启动mysql服务

    在<计算机网络>课程中曾学过net命令,可以用于启动后台服务.在mysql中,net命令用于启动后台服务器进程mysqld,即后台服务. 不过,如果在普通用户模式下net start my ...

  8. redis在Windows下以后台服务一键搭建集群(单机--伪集群)

    redis在Windows下以后台服务一键搭建集群(单机--伪集群) 一.概述 此教程介绍如何在windows系统中同一台机器上布置redis伪集群,同时要以后台服务的模式运行.布置以脚本的形式,一键 ...

  9. sql server 索引总结一

    一.存储结构 在SQL Server中,有许多不同的可用排列规则选项. 二进制:按字符的数字表示形式排序(ASCII码中,用数字32表示空格,用68表示字母"D").因为所有内容都 ...

  10. 关于VPS主机KVM/OPENVZ/CN2区别与含义

    1.OPENVZ OpenVZ是基于Linux内核和作业系统的操作系统级虚拟化技术.OpenVZ允许物理服务器运行多个操作系统,被称虚拟专用服务器(VPS,Virtual Private Server ...