hdoj 2955 Robberies
Robberies
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 15522 Accepted Submission(s): 5708

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.
Bank j contains Mj millions, and the probability of getting caught from robbing it is Pj .
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.
#include<stdio.h>
#include<string.h>
#define MAX 10001
#define max(x,y)(x>y?x:y)
int price[110];
double wei[110],dp[MAX];
int main()
{
int n,j,i,t,money;
double p,w;
scanf("%d",&t);
while(t--)
{
scanf("%lf%d",&w,&n);
money=0;
for(i=0;i<n;i++)
{
scanf("%d%lf",&price[i],&wei[i]);
money+=price[i];
wei[i]=1-wei[i];
}
memset(dp,0,sizeof(dp));
dp[0]=1;
for(i=0;i<n;i++)
{
for(j=money;j>=price[i];j--)
{
dp[j]=max(dp[j],dp[j-price[i]]*wei[i]);
}
}
p=1-w;
for(i=money;i>=0;i--)
{
if(dp[i]>=p)
{
printf("%d\n",i);
break;
}
}
}
return 0;
}
hdoj 2955 Robberies的更多相关文章
- HDOJ.2955 Robberies (01背包+概率问题)
Robberies 算法学习-–动态规划初探 题意分析 有一个小偷去抢劫银行,给出来银行的个数n,和一个概率p为能够逃跑的临界概率,接下来有n行分别是这个银行所有拥有的钱数mi和抢劫后被抓的概率pi, ...
- HDOJ 2955 Robberies (01背包)
10397780 2014-03-26 00:13:51 Accepted 2955 46MS 480K 676 B C++ 泽泽 http://acm.hdu.edu.cn/showproblem. ...
- 【HDOJ】2955 Robberies
01背包.将最大金额作为容量v.概率做乘法. #include <stdio.h> #include <string.h> #define mymax(a, b) (a> ...
- HDU 2955 Robberies 背包概率DP
A - Robberies Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submi ...
- Hdu 2955 Robberies 0/1背包
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- [HDU 2955]Robberies (动态规划)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 题意是给你一个概率P,和N个银行 现在要去偷钱,在每个银行可以偷到m块钱,但是有p的概率被抓 问 ...
- hdu 2955 Robberies 0-1背包/概率初始化
/*Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- hdu 2955 Robberies
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- hdu 2955 Robberies 背包DP
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
随机推荐
- cocos2dx输出信息重定向到控制台
重定向输出到控制台,方便调试,代码: // uncomment below line, open debug console #define USE_WIN32_CONSOLE int APIENTR ...
- MXNet在64位Win7下的编译安装
注:本文原创,作者:Noah Zhang (http://www.cnblogs.com/noahzn/) 我笔记本配置比较低,想装个轻量级的MXNet试试,装完之后报错,不是有效的应用程序,找不到 ...
- 使用Yeoman搭建 AngularJS 应用 (1) —— 介绍
原文地址:http://yeoman.io/learning/ Yeoman 是一个通用的可以创建多种应用的基架系统.它帮助用户快速搭建新的项目,并且可以简化已存在项目的维护过程. Yeoman是不限 ...
- Swift 中的 Runtime
即使在 Swift APP 中没有一行 Object-c 的代码,每个 APP 也都会在 Object-c runtime 中运行,为动态任务分发和运行时对象关联开启了一个世界.更确切地说,可能在仅使 ...
- python image模块
Image 模块 Image 模块提供了同名的类用来表示PIL的图像.Image模块还提供了许多工厂(factory)函数,包块从文件加载图像的函数,以及创建新图像的函数. 例子 下面的脚本加 ...
- python re.sub
python re.sub python re.sub属于python正则的标准库,主要是的功能是用正则匹配要替换的字符串然后把它替换成自己想要的字符串的方法下面给个例子:import relin ...
- hbase安装(zookeeper等)
文库:http://wenku.baidu.com/link?url=5mnYL7ZuxUBWZnrnmak4JRVF5fJquJmjgmZy788i7UW8lUk4QXD8Nc_haPz33vjt9 ...
- IEHelper - Internet Explorer Helper Class
http://www.codeproject.com/Articles/4411/IEHelper-Internet-Explorer-Helper-Class Discussions (81) IE ...
- iOS上获得MAC地址
很多时候我们都需要唯一来确定一台设备,苹果设备本来有个UDID号,可以实现这个目的.在iOS5.0以前,还有一个uniqueIdentifier的API用来获得这个number.不过iOS5之后,这个 ...
- Android 内核初识(5)Zygote进程
简介 Zygote本身是一个Native的应用程序,和驱动.内核等均无关系.Zygote是由init进程根据init.rc文件中的配置项而创建的. zygote最初的名字叫“app_process”, ...